添加功能
This commit is contained in:
@@ -21,6 +21,8 @@ class HrContract(models.Model):
|
||||
date_of_entry = fields.Date(related='employee_id.entry_date', string="入职时间")
|
||||
salary_group_id = fields.Many2one('yuthon.salary.group', string="工资单分组", store=True, index=True)
|
||||
is_internship = fields.Boolean(string="实习期", compute='_compute_name', store=True)
|
||||
date_end = fields.Date(string="合同结束时间", compute='_compute_date_end', store=True)
|
||||
termination_date = fields.Date(string="合同中止时间")
|
||||
work_entry_source = fields.Selection([
|
||||
('calendar', '考勤安排'),
|
||||
('attendance', 'Attendances'),
|
||||
@@ -39,6 +41,14 @@ class HrContract(models.Model):
|
||||
documents_ids = fields.Many2many('ir.attachment', string="合同附件")
|
||||
is_company = fields.Boolean(string="本公司", default=True, compute='_compute_is_company', search='_search_part_of_company')
|
||||
|
||||
@api.depends('employee_id')
|
||||
def _compute_date_end(self):
|
||||
for record in self:
|
||||
if record.employee_id.retire_date:
|
||||
record.date_end = record.employee_id.retire_date
|
||||
else:
|
||||
record.date_end = date(2070, 1, 1)
|
||||
|
||||
def write(self, vals):
|
||||
"""在写入时自动更新合同状态"""
|
||||
today = fields.Date.today()
|
||||
@@ -87,13 +97,16 @@ class HrContract(models.Model):
|
||||
('state', 'not in', ['cancel']),
|
||||
])
|
||||
for contract in active_contracts:
|
||||
if not contract.date_end:
|
||||
contract.state = 'open'
|
||||
else:
|
||||
if contract.date_end < today:
|
||||
contract.state = 'close'
|
||||
else:
|
||||
contract.state = 'open'
|
||||
new_state = 'open' if not contract.date_end or contract.date_end >= today else 'close'
|
||||
if new_state == 'open':
|
||||
conflicting_contracts = self.search([
|
||||
('id', '!=', contract.id),
|
||||
('employee_id', '=', contract.employee_id.id),
|
||||
('state', '=', 'open'),
|
||||
])
|
||||
if conflicting_contracts:
|
||||
continue
|
||||
contract.state = new_state
|
||||
|
||||
@api.depends_context('uid', 'company')
|
||||
@api.depends('company_id')
|
||||
|
||||
@@ -26,11 +26,18 @@
|
||||
<xpath expr="//field[@name='employee_id']" position="after">
|
||||
<field name="code"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='date_end']" position="attributes">
|
||||
<attribute name="readonly">0</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='date_end']" position="after">
|
||||
<field name="termination_date"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='other']" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='contract_type_id']" position="after">
|
||||
<field name="is_probation"/>
|
||||
<field name="termination_date"/>
|
||||
<field name="salary_day" invisible="not is_internship"/>
|
||||
<field name="salary_group_id" options="{'no_create': True}"/>
|
||||
<field name="is_internship" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user