[IMP] hr_contract: automatically expire contract when past end date
Automatically closes contracts when the end date is set in the past. closes odoo/odoo#90714 Taskid: 2845368 Related: odoo/enterprise#27037 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -221,6 +221,10 @@ class Contract(models.Model):
|
||||
if vals.get('state') == 'close':
|
||||
for contract in self.filtered(lambda c: not c.date_end):
|
||||
contract.date_end = max(date.today(), contract.date_start)
|
||||
date_end = vals.get('date_end')
|
||||
if self.env.context.get('close_contract', True) and date_end and fields.Date.from_string(date_end) < fields.Date.context_today(self):
|
||||
for contract in self.filtered(lambda c: c.state == 'open'):
|
||||
contract.state = 'close'
|
||||
|
||||
calendar = vals.get('resource_calendar_id')
|
||||
if calendar:
|
||||
|
||||
@@ -67,3 +67,12 @@ class TestHrContracts(TestContractCommon):
|
||||
self.contract = self.contracts.create(self.test_contract)
|
||||
self.apply_cron()
|
||||
self.assertEqual(self.contract.state, 'open')
|
||||
|
||||
def test_contract_auto_expire(self):
|
||||
self.test_contract.update(dict(date_start=date.today() - relativedelta(days=10), state='open'))
|
||||
self.contract = self.contracts.create(self.test_contract)
|
||||
self.apply_cron()
|
||||
self.assertEqual(self.contract.state, 'open')
|
||||
|
||||
self.contract.date_end = date.today() - relativedelta(days=3)
|
||||
self.assertEqual(self.contract.state, 'close')
|
||||
|
||||
Reference in New Issue
Block a user