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):
|
||||
_name = 'student.student'
|
||||
_description = 'Student Management'
|
||||
|
||||
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')
|
||||
gender = fields.Selection([
|
||||
('male', 'Nam giới'),
|
||||
('female', 'Nữ giới')
|
||||
])
|
||||
], default='male')
|
||||
email = fields.Char(string='Email', required=True, unique=True)
|
||||
phone = fields.Char(string='Số điện thoại')
|
||||
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()})
|
||||
Reference in New Issue
Block a user