update education module

This commit is contained in:
2025-02-22 10:32:13 +07:00
parent 2b170da354
commit ab34ac054b
15 changed files with 337 additions and 39 deletions
+3 -1
View File
@@ -2,4 +2,6 @@
from . import education_class
from . import education_class_group
from . import education_student
from . import education_student
from . import education_school
from . import education_student_level
+23 -7
View File
@@ -2,13 +2,29 @@
from odoo import models, fields
class EducationClass(models.Model):
_name = 'education.class'
_description = 'Education Class'
_name = "education.class"
_description = "Education Class"
name = fields.Char(string='Name', required=True)
class_group_id = fields.Many2one('education.class.group', string='Class Group', ondelete='restrict')
next_class_id = fields.Many2one('education.class', string='Next Class')
name = fields.Char(string="Name", required=True)
class_group_id = fields.Many2one(
"education.class.group", string="Class Group", ondelete="restrict"
)
next_class_id = fields.Many2one("education.class", string="Next Class")
attachment_ids = fields.Many2many('ir.attachment', 'education_student_ir_attachment_rel',
'attachment_id', 'student_id', string='Attachments')
attachment_ids = fields.Many2many(
"ir.attachment",
"education_student_ir_attachment_rel",
"attachment_id",
"student_id",
string="Attachments",
)
currency_id = fields.Many2one("res.currency", string="Currency")
class_fund = fields.Monetary(string="Class Fund", currency_field="currency_id")
student_ids = fields.One2many("education.student", "class_id", string="Students")
school_id = fields.Many2one("education.school", string="School", required=True)
active = fields.Boolean(string="Active", default=True)
school_id = fields.Many2one("education.school", string="School", required=True)
teacher_ids = fields.Many2many("res.partner", string="Teachers")
+15 -2
View File
@@ -1,8 +1,21 @@
from odoo import fields, models
from odoo import fields, models, api
from odoo.exceptions import ValidationError
class EductionClassGroup(models.Model):
_name = 'education.class.group'
_description = 'Education Class Group'
_order = 'sequence'
class_ids = fields.One2many('education.class', 'class_group_id', string='Class of Groups')
name = fields.Char(string='Name', translate=True, required=True)
parent_id = fields.Many2one('education.class.group', string='Parent Group', ondelete='restrict')
child_ids = fields.One2many('education.class.group', string='Child Groups', ondelete='restrict')
class_ids = fields.One2many('education.class', 'class_group_id', string='Class of Groups')
_parent_store = True
_parent_name = "parent_id"
parent_path = fields.Char(index=True)
@api.constraints('parent_id')
def _check_hierarchy(self):
if not self._check_recursion():
raise ValidationError('Error! You cannot create recursivecategories.')
+11
View File
@@ -0,0 +1,11 @@
from odoo import fields, models
class EductionSchool(models.Model):
_name = 'education.school'
_description = 'School'
name = fields.Char(string='Name', translate=True, required=True)
code = fields.Char(string='Code', copy=False)
class_ids = fields.One2many('education.class', 'school_id', string='Classes')
is_private = fields.Boolean(string='Is Private', groups='viin_education.viin_education_group_admin')
+83 -7
View File
@@ -1,10 +1,86 @@
from odoo import models, fields
from odoo import models, fields, api
from odoo.exceptions import ValidationError
from datetime import date
class EducationStudent(models.Model):
_name = 'education.student'
_name = "education.student"
name = fields.Char(string="Name")
student_code = fields.Char(string='Student Code')
class_id = fields.Many2one('education.class', string='Class')
_name = "education.student"
_description = "Education Student"
def get_student_has_class(self):
return self.env['education.student'].search([('class_id', '!=', False)])
name = fields.Char(string="Name", required=True, translate=True)
student_code = fields.Char(
string="Student Code", required=True, index=True, help="Student ID is unique"
)
gender = fields.Selection(
[("male", "Male"), ("female", "Female"), ("other", "Other")],
string="Gender",
default="male",
)
date_of_birth = fields.Date(string="Date of Birth")
age = fields.Integer(
string="Age",
compute="_compute_age",
inverse="_inverse_age",
search="_search_age",
store=False, # tùy chọn
compute_sudo=True,
)
active = fields.Boolean(string="Active", default=True)
notes = fields.Text(string="Internal Notes")
description = fields.Html(string="Description", sanitize=True, strip_style=False)
attached_file = fields.Binary("Attached File", groups="base.group_user")
total_score = fields.Float(string="Total Score", digits="Score")
write_date = fields.Datetime(string="Last Updated on")
currency_id = fields.Many2one("res.currency", string="Currency")
amount_paid = fields.Monetary("Amount Paid")
@api.depends("date_of_birth")
def _compute_age(self):
curent_year = fields.Date.today().year
for r in self:
if r.date_of_birth:
r.age = curent_year - r.date_of_birth.year
else:
r.age = 0
def get_student_has_class(self):
return self.env["education.student"].search([("class_id", "!=", False)])
_sql_constraints = [
(
"student_code_unique",
"unique(student_code)",
"The student code must be unique!",
),
(
"check_total_score",
"CHECK(total_score >= 0)",
"The Total Score must be greater than 0!",
),
]
@api.constrains("date_of_birth")
def _check_date_of_birth(self):
for r in self:
if r.date_of_birth > fields.Date.today():
raise ValidationError("Date of Birth must be in the past")
def _inverse_age(self):
for r in self:
if r.age and r.date_of_birth:
curent_year = fields.Date.today().year
dob_year = curent_year - r.age
dob_month = r.date_of_birth.month
dob_day = r.date_of_birth.day
date_of_birth = date(dob_year, dob_month, dob_day)
r.date_of_birth = date_of_birth
def _search_age(self, operator, value):
new_year = fields.Date.today().year - value
new_value = date(1, 1, new_year)
# age > value => date_of_birth < new_value
operator_map = {">": "<", ">=": "<=", "<": ">", "<=": ">="}
new_operator = operator_map.get(operator, operator)
return [("date_of_birth", new_operator, new_value)]
@@ -0,0 +1,11 @@
from odoo import fields, models
class StudentLevel(models.Model):
_name = 'student.level'
_description = 'Student Level'
_order = 'sequence, name'
_rec_name = 'code'
code = fields.Char(string='Code', required=True)
name = fields.Char(string='Name', translate=True, required=True)
sequence = fields.Integer(string='Sequence', default=1)