37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from odoo import api, fields, models, _
|
|
|
|
class AcademyStudent(models.Model):
|
|
_name = 'academy.student'
|
|
_description = 'Academy Student'
|
|
|
|
name = fields.Char(string='Tên học sinh', required=True)
|
|
code = fields.Char(string='Mã học sinh', required=True, copy=False, readonly=True, default=lambda self: _(' '))
|
|
birth_date = fields.Date(string='Ngày sinh')
|
|
email = fields.Char(string='Email')
|
|
phone = fields.Char(string='Số điện thoại')
|
|
course_ids = fields.Many2many('academy.course', string='Các khóa học học sinh đăng ký')
|
|
state = fields.Selection([
|
|
('draft', 'Mới đăng ký'),
|
|
('confirmed', 'Đã xác nhận'),
|
|
('graduated', 'Đã tốt nghiệp'),
|
|
], string='Trạng thái', default='draft')
|
|
|
|
_sql_constraints = [(
|
|
'code_unique',
|
|
'unique(code)',
|
|
'Mã học sinh phải là duy nhất!'
|
|
)]
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if vals.get('code', _(' ')) == _(' '):
|
|
vals['code'] = self.env['ir.sequence'].next_by_code('academy.student') or 'HS001'
|
|
return super().create(vals_list)
|
|
|
|
def action_confirm(self):
|
|
self.state = 'confirmed'
|
|
|
|
def action_graduate(self):
|
|
self.state = 'graduated'
|