update education module
This commit is contained in:
@@ -5,4 +5,5 @@ from . import education_class_group
|
||||
from . import education_student
|
||||
from . import education_school
|
||||
from . import education_student_level
|
||||
from . import res_partner
|
||||
from . import res_partner
|
||||
|
||||
|
||||
@@ -25,5 +25,36 @@ class EducationClass(models.Model):
|
||||
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)
|
||||
active = fields.Boolean(default=True)
|
||||
teacher_ids = fields.Many2many("res.partner", string="Teachers")
|
||||
|
||||
def get_all_students(self):
|
||||
# Khởi tạo đối tượng education.student (đây là một recordset rỗng của model education.student)
|
||||
student = self.env["education.student"]
|
||||
all_students = student.search([])
|
||||
print("All Students: ", all_students)
|
||||
|
||||
def create_classes(self):
|
||||
# Giá trị để tạo bản ghi student 01
|
||||
student_01 = {
|
||||
"name": "Student 01",
|
||||
"student_code": "STD1",
|
||||
"school_id": self.school_id.id,
|
||||
}
|
||||
# Giá trị để tạo bản ghi student 02
|
||||
student_02 = {
|
||||
"name": "Student 02",
|
||||
"student_code": "STD2",
|
||||
"school_id": self.school_id.id,
|
||||
}
|
||||
# Giá trị để tạo bản ghi lớp học
|
||||
class_value = {
|
||||
"name": "Class 01",
|
||||
"school_id": self.school_id.id,
|
||||
"student_ids": [(0, 0, student_01), (0, 0, student_02)],
|
||||
}
|
||||
record = self.env["education.class"].create(class_value)
|
||||
|
||||
def change_class_name(self):
|
||||
self.ensure_one()
|
||||
self.name = "Class 12A1"
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
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'
|
||||
|
||||
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')
|
||||
|
||||
_name = "education.class.group"
|
||||
_description = "Education Class Group"
|
||||
_order = "sequence"
|
||||
sequence = fields.Integer(string="Sequence", default=0)
|
||||
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", "parent_id", string="Child Groups"
|
||||
)
|
||||
_parent_store = True
|
||||
_parent_name = "parent_id"
|
||||
parent_path = fields.Char(index=True)
|
||||
|
||||
@api.constrains('parent_id')
|
||||
class_ids = fields.One2many(
|
||||
"education.class", "class_group_id", string="Class of Groups"
|
||||
)
|
||||
|
||||
@api.constrains("parent_id")
|
||||
def _check_hierarchy(self):
|
||||
if not self._check_recursion():
|
||||
raise ValidationError('Error! You cannot create recursivecategories.')
|
||||
raise ValidationError("Error! You cannot create recursivecategories.")
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class EductionSchool(models.Model):
|
||||
|
||||
_name = 'education.school'
|
||||
_description = 'School'
|
||||
_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')
|
||||
name = fields.Char(string="Name", translate=True, required=True)
|
||||
code = fields.Char(string="Code", copy=False)
|
||||
address = fields.Char(string="Address")
|
||||
class_ids = fields.One2many("education.class", "school_id", string="Classes")
|
||||
is_private = fields.Boolean(
|
||||
string="Is Private", groups="education.education_group_admin"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import ValidationError
|
||||
from datetime import date
|
||||
from odoo import _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class EducationStudent(models.Model):
|
||||
@@ -18,7 +20,7 @@ class EducationStudent(models.Model):
|
||||
string="Gender",
|
||||
default="male",
|
||||
)
|
||||
date_of_birth = fields.Date(string="Date of Birth")
|
||||
date_of_birth = fields.Date(string="Date of Birth",)
|
||||
age = fields.Integer(
|
||||
string="Age",
|
||||
compute="_compute_age",
|
||||
@@ -26,28 +28,26 @@ class EducationStudent(models.Model):
|
||||
search="_search_age",
|
||||
store=False, # tùy chọn
|
||||
compute_sudo=True,
|
||||
readonly=True,
|
||||
)
|
||||
active = fields.Boolean(string="Active", default=True)
|
||||
notes = fields.Text(string="Internal Notes")
|
||||
description = fields.Html(string="Description", sanitize=True, strip_style=False)
|
||||
dropout_reason = fields.Text(string="Dropout Reason")
|
||||
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")
|
||||
class_id = fields.Many2one("education.class", string="Education Class")
|
||||
@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)])
|
||||
|
||||
amount_paid = fields.Monetary("Amount Paid", currency_field="currency_id")
|
||||
class_id = fields.Many2one("education.class", string="Class", ondelete="restrict")
|
||||
school_id = fields.Many2one("education.school", string="School")
|
||||
school_code = fields.Char(related="school_id.code", string="School Code")
|
||||
school_address = fields.Char(related="school_id.address", string="School Address")
|
||||
state = fields.Selection(
|
||||
string="Status",
|
||||
selection=[("new", "New"), ("studying", "Studying"), ("off", "Off")],
|
||||
default="new",
|
||||
)
|
||||
_sql_constraints = [
|
||||
(
|
||||
"student_code_unique",
|
||||
@@ -61,6 +61,28 @@ class EducationStudent(models.Model):
|
||||
),
|
||||
]
|
||||
|
||||
@api.model
|
||||
def is_allowed_state(self, current_state, new_state):
|
||||
allowed_states = [
|
||||
("new", "studying"),
|
||||
("studying", "off"),
|
||||
("off", "studying"),
|
||||
("new", "off"),
|
||||
]
|
||||
return (current_state, new_state) in allowed_states
|
||||
|
||||
@api.depends("date_of_birth", "age")
|
||||
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 + 1
|
||||
else:
|
||||
r.age = 0
|
||||
|
||||
def get_student_has_class(self):
|
||||
return self.env["education.student"].search([("class_id", "!=", False)])
|
||||
|
||||
@api.constrains("date_of_birth")
|
||||
def _check_date_of_birth(self):
|
||||
for r in self:
|
||||
@@ -84,3 +106,31 @@ class EducationStudent(models.Model):
|
||||
operator_map = {">": "<", ">=": "<=", "<": ">", "<=": ">="}
|
||||
new_operator = operator_map.get(operator, operator)
|
||||
return [("date_of_birth", new_operator, new_value)]
|
||||
|
||||
def change_student_state(self, state):
|
||||
for student in self:
|
||||
if student.is_allowed_state(student.state, state):
|
||||
student.state = state
|
||||
else:
|
||||
raise UserError(
|
||||
_("Changing student status from %s to %s is not allowed.")
|
||||
% (student.state, state)
|
||||
)
|
||||
|
||||
def change_to_new(self):
|
||||
self.change_student_state("new")
|
||||
|
||||
def change_to_studying(self):
|
||||
self.change_student_state("studying")
|
||||
|
||||
def change_to_off(self):
|
||||
self.change_student_state("off")
|
||||
|
||||
def find_student(self):
|
||||
domain = ["|", ("name", "ilike", "John"), ("class_id.name", "=", "12A1")]
|
||||
students = self.search(domain)
|
||||
|
||||
def action_dropout(self):
|
||||
return self.env.ref("education.education_student_dropout_wizard_action").read()[
|
||||
0
|
||||
]
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from odoo import fields, models
|
||||
|
||||
class StudentLevel(models.Model):
|
||||
_name = 'education.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)
|
||||
class StudentLevel(models.Model):
|
||||
_name = "education.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)
|
||||
|
||||
Reference in New Issue
Block a user