odoo_18_Education_management/models/application.py

121 lines
4.4 KiB
Python
Raw Permalink Normal View History

2025-07-29 05:25:05 +00:00
from odoo import models, fields, api
from odoo.exceptions import ValidationError
import re
import base64
class SchoolApplication(models.Model):
_name = 'school.application'
_description = 'Student Application'
_order = 'name'
_rec_name = 'name'
2025-08-04 07:27:45 +00:00
_inherit = ['mail.thread', 'mail.activity.mixin']
2025-07-29 05:25:05 +00:00
2025-08-06 09:23:00 +00:00
# Link to res.partner
partner_id = fields.Many2one('res.partner', string="Student Contact", ondelete="cascade")
# Basic Info
name = fields.Char(string="Student Name", required=True)
roll_no = fields.Char(string="Roll Number", readonly=False)
email = fields.Char(string="Email")
phone_no = fields.Char(string="Phone Number")
image = fields.Binary("Profile Photo", store=True)
2025-07-29 05:25:05 +00:00
address = fields.Text(string="Address")
2025-08-06 09:23:00 +00:00
# Class and Academic Info
2025-08-04 07:27:45 +00:00
class_name = fields.Selection([
2025-08-06 09:23:00 +00:00
('1', 'Class 1'), ('2', 'Class 2'), ('3', 'Class 3'),
('4', 'Class 4'), ('5', 'Class 5'), ('6', 'Class 6'),
('7', 'Class 7'), ('8', 'Class 8'), ('9', 'Class 9'),
('10', 'Class 10'), ('11', 'Class 11'), ('12', 'Class 12'),
2025-08-04 07:27:45 +00:00
], string="Class", required=True)
2025-08-06 09:23:00 +00:00
2025-08-04 07:27:45 +00:00
academic_year = fields.Char(string="Academic Year")
2025-07-29 05:25:05 +00:00
gender = fields.Selection([
2025-08-06 09:23:00 +00:00
('male', 'Male'), ('female', 'Female'), ('other', 'Other')
2025-07-29 05:25:05 +00:00
], string="Gender")
2025-08-06 09:23:00 +00:00
2025-07-29 05:25:05 +00:00
date_of_birth = fields.Date(string="Date of Birth")
parent_email = fields.Char(string="Parent Email")
2025-08-06 09:23:00 +00:00
2025-07-29 05:25:05 +00:00
blood_group = fields.Selection([
2025-08-06 09:23:00 +00:00
('a+', 'A+'), ('a-', 'A-'), ('b+', 'B+'), ('b-', 'B-'),
('ab+', 'AB+'), ('ab-', 'AB-'), ('o+', 'O+'), ('o-', 'O-')
2025-07-29 05:25:05 +00:00
], string="Blood Group")
2025-08-06 09:23:00 +00:00
2025-07-29 05:25:05 +00:00
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")
2025-08-06 09:23:00 +00:00
2025-07-29 05:25:05 +00:00
caste = fields.Selection([
2025-08-06 09:23:00 +00:00
('general', 'General'), ('OBC', 'OBC'), ('SC', 'SC'),
('ST', 'ST'), ('other', 'Other')
2025-07-29 05:25:05 +00:00
], string="Caste")
2025-08-06 09:23:00 +00:00
2025-07-29 05:25:05 +00:00
status = fields.Selection([
('pending', 'Pending'),
('approved', 'Approved'),
('rejected', 'Rejected')
], default='pending')
2025-08-06 09:23:00 +00:00
# Parent Info
2025-07-29 05:25:05 +00:00
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")
2025-08-06 09:23:00 +00:00
@api.onchange('roll_no')
def _onchange_roll_no(self):
"""Auto-generate roll number only when it's empty and user clicks the field."""
if not self.roll_no:
self.roll_no = self.env['ir.sequence'].next_by_code('school.application')
# Constraint on phone number
2025-07-29 05:25:05 +00:00
@api.constrains('phone_no')
def _check_phone_no(self):
for record in self:
2025-08-06 09:23:00 +00:00
if record.phone_no and not re.fullmatch(r'\d{10}', record.phone_no):
2025-07-29 05:25:05 +00:00
raise ValidationError("Phone number must contain exactly 10 digits.")
2025-08-06 09:23:00 +00:00
# Show ID card action
2025-08-04 07:27:45 +00:00
def action_show_id_card(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': 'ID Card',
'view_mode': 'form',
'res_model': 'school.application',
'res_id': self.id,
'view_id': self.env.ref('school_management.view_school_id_card_form').id,
2025-08-06 09:23:00 +00:00
'target': 'new',
2025-08-04 07:27:45 +00:00
}
2025-07-29 05:25:05 +00:00
2025-08-06 09:23:00 +00:00
# Optional: Sync partner details with application
@api.onchange('partner_id')
def _onchange_partner_id(self):
if self.partner_id:
self.name = self.partner_id.name
self.email = self.partner_id.email
self.phone_no = self.partner_id.phone
self.image = self.partner_id.image_1920
self.address = self.partner_id.contact_address
2025-08-04 07:27:45 +00:00
2025-08-06 09:23:00 +00:00
def print_id_card(self):
self.ensure_one()
return self.env.ref('school_management.report_school_id_card').report_action(self)