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
+1
View File
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<template id="awesome_owl.playground" name="Awesome T-Shirt thank you"> <template id="awesome_owl.playground" name="Awesome T-Shirt thank you">
+3 -3
View File
@@ -27,8 +27,8 @@
'views/templates.xml', 'views/templates.xml',
], ],
# only loaded in demonstration mode # only loaded in demonstration mode
'demo': [ # 'demo': [
'demo/demo.xml', # 'demo/demo.xml',
], # ],
} }
+3 -1
View File
@@ -2,4 +2,6 @@
from . import education_class from . import education_class
from . import education_class_group 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 from odoo import models, fields
class EducationClass(models.Model): class EducationClass(models.Model):
_name = 'education.class' _name = "education.class"
_description = 'Education Class' _description = "Education Class"
name = fields.Char(string='Name', required=True) name = fields.Char(string="Name", required=True)
class_group_id = fields.Many2one('education.class.group', string='Class Group', ondelete='restrict') class_group_id = fields.Many2one(
next_class_id = fields.Many2one('education.class', string='Next Class') "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_ids = fields.Many2many(
'attachment_id', 'student_id', string='Attachments') "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): class EductionClassGroup(models.Model):
_name = 'education.class.group' _name = 'education.class.group'
_description = 'Education Class Group' _description = 'Education Class Group'
_order = 'sequence' _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): class EducationStudent(models.Model):
_name = 'education.student' _name = "education.student"
name = fields.Char(string="Name") _name = "education.student"
student_code = fields.Char(string='Student Code') _description = "Education Student"
class_id = fields.Many2one('education.class', string='Class')
def get_student_has_class(self): name = fields.Char(string="Name", required=True, translate=True)
return self.env['education.student'].search([('class_id', '!=', False)]) 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)
@@ -0,0 +1,44 @@
<odoo>
<record id="module_education_category" model="ir.module.category">
<field name="name">Education</field>
<field name="sequence">10</field>
</record>
<record id="module_education_category_user" model="ir.module.category">
<field name="name">Education</field>
<field name="parent_id" ref="module_education_category" />
<field name="description">Helps you handle education application</field>
<field name="sequence">10</field>
</record>
<record id="education_group_user" model="res.groups">
<field name="name">User</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
<field name="category_id" ref="module_education_category_user" />
<field name="comment">Users belong to this group can use this application</field>
</record>
<record id="education_group_admin" model="res.groups">
<field name="name">Administrator</field>
<field name="implied_ids" eval="[(4, ref('education_group_user'))]" />
<field name="category_id" ref="module_education_category_user" />
<field name="users" eval="[(4, ref('base.user_root')),(4, ref('base.user_admin'))]" />
<field name="comment">Users belong to this group can control this application</field>
</record>
<record id="education_school_rule_user" model="ir.rule">
<field name="name">School: Only see the school is not private</field>
<field name="model_id" ref="model_education_school" />
<field name="groups" eval="[(4, ref('education.education_group_user'))]" />
<field name="domain_force">[('is_private', '=', False)]</field>
</record>
<record id="education_school_rule_admin" model="ir.rule">
<field name="name">School: See all schools</field>
<field name="model_id" ref="model_education_school" />
<field name="groups" eval="[(4, ref('education.education_group_admin'))]" />
<field name="domain_force">[(1, '=', 1)]</field>
</record>
<record id="education_group_allow_manager_class" model="res.groups">
<field name="name">Allow class management</field>
</record>
</odoo>
+3
View File
@@ -1,2 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_education_education,education.education,model_education_education,base.group_user,1,1,1,1 access_education_education,education.education,model_education_education,base.group_user,1,1,1,1
access_education_school_user,education.school user,model_education_school,education_group_user,1,0,0,0
access_education_school_admin,education.school admin,model_education_school,education_group_admin,1,1,1,1
access_education_class_allow_manager,education.class allow_manager,model_education_class,education_group_allow_manager_class,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_education_education education.education model_education_education base.group_user 1 1 1 1
3 access_education_school_user education.school user model_education_school education_group_user 1 0 0 0
4 access_education_school_admin education.school admin model_education_school education_group_admin 1 1 1 1
5 access_education_class_allow_manager education.class allow_manager model_education_class education_group_allow_manager_class 1 1 1 1
-19
View File
@@ -1,19 +0,0 @@
<odoo>
<data>
<record id="education_class_view_list" model="ir.ui.view">
<field name="name">education.class.list</field>
<field name="model">education.class</field>
<field name="arch" type="xml">
<list string="Class list">
<field name="name"/>
</list>
</field>
</record>
<record id="education_class_action" model="ir.actions.act_window">
<field name="name">Class</field>
<field name="res_model">education.class</field>
<field name="view_mode">list,form</field>
</record>
<menuitem id="education_class_menu" action="education_class_action" parent="education_configuration_menu_root" sequence="10"/>
</data>
</odoo>
+51
View File
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="education_class_view_form" model="ir.ui.view">
<field name="name">education.class.form</field>
<field name="model">education.class</field>
<field name="arch" type="xml">
<form string="Class Form">
<sheet>
<widget name="web_ribbon" title="Archived" bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}" />
<field name="active" invisible="1" />
<group>
<group>
<field name="name" />
<field name="school_id" />
<field name="class_group_id" />
</group>
<group>
<field name="next_class_id" />
<field name="company_id" groups="base.group_multi_company" />
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="education_class_view_list" model="ir.ui.view">
<field name="name">education.class.list</field>
<field name="model">education.class</field>
<field name="arch" type="xml">
<list string="Class list">
<field name="name" />
<field name="class_group_id" />
<field name="next_class_id" />
<field name="school_id" />
</list>
</field>
</record>
<record id="education_class_action" model="ir.actions.act_window">
<field name="name">Class</field>
<field name="res_model">education.class</field>
<field name="view_mode">list,form</field>
</record>
</data>
<menuitem id="education_class_allow_manager_menu"
action="education_class_action"
parent="education_management_menu_root"
groups="education.education_group_allow_manager_class"
sequence="100" />
</odoo>
@@ -0,0 +1,3 @@
<odoo>
</odoo>
@@ -0,0 +1,21 @@
<odoo>
<record id="student_level_view_form" model="ir.ui.view">
<field name="name">student.level.form</field>
<field name="model">student.level</field>
<field name="arch" type="xml">
<form string="Student Level Form">
<sheet>
<group>
<group>
<field name="name"/>
<field name="sequence"/>
</group>
<group>
<field name="code"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="education_student_view_form" model="ir.ui.view">
<field name="name">education.student.form</field>
<field name="model">education.student</field>
<field name="arch" type="xml">
<form string="Student Form">
<sheet>
<group>
<group>
<field name="name" />
<field name="student_code" />
<field name="gender" />
<field name="date_of_birth" />
<field name="age" />
<field name="currency_id" />
<field name="amount_paid" />
</group>
<group>
<field name="total_score" />
<field name="attached_file" />
<field name="write_date" />
</group>
</group>
<group>
<field name="notes" />
</group>
<group>
<field name="description" />
</group>
</sheet>
</form>
</field>
</record>
<record id="education_student_view_list" model="ir.ui.view">
<field name="name">education.student.list</field>
<field name="model">education.student</field>
<field name="arch" type="xml">
<tree string="Student list">
<field name="name" />
<field name="student_code" />
<field name="class_id" />
</tree>
</field>
</record>
<record id="education_student_view_search" model="ir.ui.view">
<field name="name">education.student.search</field>
<field name="model">education.student</field>
<field name="arch" type="xml">
<search string="Students Search">
<field name="name"
filter_domain="['|', '|', ('name', 'ilike', self), ('student_code', '=', self)" />
<field name="class_id" />
</search>
</field>
</record>
<record id="education_student_action" model="ir.actions.act_window">
<field name="name">Students</field>
<field name="res_model">education.student</field>
<field name="view_mode">list,form</field>
</record>
<menuitem name="Education Manager" id="education_student_menu_root" />
<menuitem id="education_student_menu" action="education_student_action"
parent="education_student_menu_root" name="Students" sequence="50" />
</odoo>