action generate student id
This commit is contained in:
@@ -1,16 +1,30 @@
|
|||||||
from odoo import fields, models
|
from odoo import fields, models, api
|
||||||
|
|
||||||
class StudentStudent(models.Model):
|
class StudentStudent(models.Model):
|
||||||
_name = 'student.student'
|
_name = 'student.student'
|
||||||
_description = 'Student Management'
|
_description = 'Student Management'
|
||||||
|
|
||||||
name = fields.Char(string='Tên học sinh', required=True)
|
name = fields.Char(string='Tên học sinh', required=True)
|
||||||
student_id = fields.Char(string='Mã học sinh', unique=True)
|
student_id = fields.Char(string='Mã học sinh', unique=True, copy=False, required=True, default=lambda self: self._generate_student_id())
|
||||||
birth_date = fields.Date(string='Ngày sinh')
|
birth_date = fields.Date(string='Ngày sinh')
|
||||||
gender = fields.Selection([
|
gender = fields.Selection([
|
||||||
('male', 'Nam giới'),
|
('male', 'Nam giới'),
|
||||||
('female', 'Nữ giới')
|
('female', 'Nữ giới')
|
||||||
])
|
], default='male')
|
||||||
email = fields.Char(string='Email', required=True, unique=True)
|
email = fields.Char(string='Email', required=True, unique=True)
|
||||||
phone = fields.Char(string='Số điện thoại')
|
phone = fields.Char(string='Số điện thoại')
|
||||||
course_ids = fields.Many2many('student.course', string='Môn học')
|
course_ids = fields.Many2many('student.course', string='Môn học')
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _generate_student_id(self):
|
||||||
|
last_student = self.search([], order='id desc', limit=1)
|
||||||
|
new_id = int(last_student.student_id.split('-')[-1]) + 1 if last_student and last_student.student_id else 1
|
||||||
|
return f'STU-{fields.Date.today().year}-{new_id:04d}'
|
||||||
|
|
||||||
|
def generate_student_id(self):
|
||||||
|
for record in self:
|
||||||
|
record.student_id = self._generate_student_id()
|
||||||
|
|
||||||
|
def action_generate_student_id(self):
|
||||||
|
for record in self:
|
||||||
|
record.write({'student_id': self._generate_student_id()})
|
||||||
@@ -24,10 +24,14 @@
|
|||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
<field name="name" />
|
<field name="name" string="Họ tên" />
|
||||||
<field name="student_id" />
|
<div class="d-flex">
|
||||||
<field name="email" />
|
<field name="student_id" string="Mã học sinh" />
|
||||||
<field name="phone" />
|
<button name="action_generate_student_id" type="object"
|
||||||
|
string="Generate" class="btn-primary" />
|
||||||
|
</div>
|
||||||
|
<field name="email" string="Email" />
|
||||||
|
<field name="phone" string="Số điện thoại" />
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="birth_date" />
|
<field name="birth_date" />
|
||||||
|
|||||||
Reference in New Issue
Block a user