# -*- coding: utf-8 -*- from odoo import fields, models, api class Employee(models.Model): """教职工(员工)主数据模型。 这是「出勤-薪资」体系的**数据根**:出勤记录挂在员工下, 工资条在月底把「员工基本工资 + 当月出勤聚合结果」join 在一起算出来。 """ _name = 'yuthon.employee' _description = '教职工(员工)' _order = 'employee_no' # ---- 基础信息 ---- employee_no = fields.Char( string='工号', required=True, index=True, help='唯一工号,如 T2024001(教师)/ A2024002(行政)', ) name = fields.Char( string='姓名', required=True, ) gender = fields.Selection( [('male', '男'), ('female', '女')], string='性别', ) department = fields.Selection( [ ('teaching', '教学部'), ('admin', '行政部'), ('logistics', '后勤部'), ('support', '教辅部'), ], string='部门', required=True, default='teaching', ) job_title = fields.Char( string='岗位 / 职称', help='如:讲师、副教授、教务员', ) phone = fields.Char(string='联系电话') email = fields.Char(string='邮箱') # ---- 薪资相关(被 yuthon_salary 读取)---- base_salary = fields.Float( string='基本工资', default=0.0, help='教学演示用 Float;生产环境建议改用 Monetary + currency_id', ) hire_date = fields.Date(string='入职日期') active = fields.Boolean( string='在职', default=True, ) # ---- 反向关联(由 yuthon_attendance / yuthon_salary 通过 _inherit 追加)---- # attendance_ids / payslip_ids 不在此定义,避免基础模块反向依赖业务模块。 # 这是「模块解耦」的核心:根模块不知道子模块的存在。 # ---- 约束 ---- _sql_constraints = [ ('uniq_employee_no', 'unique(employee_no)', '工号已存在,不可重复!'), ] @api.constrains('base_salary') def _check_base_salary(self): for rec in self: if rec.base_salary < 0: raise models.ValidationError('基本工资不能为负数。')