Odoo-Tutorial/education/models/education_class.py
2025-02-26 16:28:17 +07:00

61 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields
class EducationClass(models.Model):
_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")
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(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"