from odoo import models, fields, api from odoo.exceptions import ValidationError import re from odoo.exceptions import UserError import base64 class SchoolApplication(models.Model): _name = 'school.application' _description = 'Student Application' _order = 'name' _rec_name = 'name' # _inherit = ['mail.thread', 'mail.activity.mixin'] name = fields.Char(string="Student Name", required=True,) email = fields.Char(string="Email", ) phone_no = fields.Char(string="Phone Number") image = fields.Binary("Profile Photo", store=True) address = fields.Text(string="Address") class_name = fields.Char(string="Class") gender = fields.Selection([ ('male', 'Male'), ('female', 'Female'), ('other', 'Other') ], string="Gender") date_of_birth = fields.Date(string="Date of Birth") parent_email = fields.Char(string="Parent Email") blood_group = fields.Selection([ ('a+', 'A+'), ('a-', 'A-'), ('b+', 'B+'), ('b-', 'B-'), ('ab+', 'AB+'), ('ab-', 'AB-'), ('o+', 'O+'), ('o-', 'O-') ], string="Blood Group") school_name = fields.Char(string="Previous School") has_disability = fields.Boolean(string="Any Disability") is_ex_service_child = fields.Boolean(string="Ex-Service Man's Child") caste = fields.Selection([ ('general', 'General'), ('OBC', 'OBC'), ('SC', 'SC'), ('ST', 'ST'), ('other','Other') ], string="Caste") status = fields.Selection([ ('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected') ], default='pending') father_name = fields.Char(string="Father's Name") father_phone = fields.Char(string="Father's Phone") mother_name = fields.Char(string="Mother's Name") mother_phone = fields.Char(string="Mother's Phone") father_occupation = fields.Char(string="Father's Occupation") mother_occupation = fields.Char(string="Mother's Occupation") # Admission Query admission_query = fields.Text(string="Admission Query") # Documents (File Uploads) birth_certificate = fields.Binary(string="Birth Certificate") birth_certificate_filename = fields.Char(string="Filename") tc_certificate = fields.Binary(string="Transfer Certificate") tc_certificate_filename = fields.Char(string="TC Filename") aadhaar_card = fields.Binary(string="Aadhaar Card") aadhaar_card_filename = fields.Char(string="Filename") @api.constrains('phone_no') def _check_phone_no(self): for record in self: if not re.fullmatch(r'\d{10}', record.phone_no or ''): raise ValidationError("Phone number must contain exactly 10 digits.") def action_send_message(self): for record in self: raise UserError("Send Message clicked for %s" % record.name) def action_log_note(self): for record in self: raise UserError("Log Note clicked for %s" % record.name) def action_schedule_activity(self): for record in self: raise UserError("Activity clicked for %s" % record.name) # def get_default_image(self): # with open('/path/to/sample.jpg', 'rb') as f: # return base64.b64encode(f.read())