[FIX] - check date_start before onchange

This commit is contained in:
sbejaoui
2018-11-30 15:59:56 +01:00
committed by Francisco Ivan Anton Prieto
parent d71261e919
commit 70c7b6fe1c

View File

@@ -82,18 +82,19 @@ class AccountAnalyticInvoiceLine(models.Model):
def _compute_state(self): def _compute_state(self):
today = fields.Date.context_today(self) today = fields.Date.context_today(self)
for rec in self: for rec in self:
if rec.is_canceled: if rec.date_start:
rec.state = 'canceled' if rec.is_canceled:
elif today < rec.date_start: rec.state = 'canceled'
rec.state = 'upcoming' elif today < rec.date_start:
elif not rec.date_end or ( rec.state = 'upcoming'
today <= rec.date_end and rec.is_auto_renew elif not rec.date_end or (
): today <= rec.date_end and rec.is_auto_renew
rec.state = 'in-progress' ):
elif today <= rec.date_end and not rec.is_auto_renew: rec.state = 'in-progress'
rec.state = 'upcoming-close' elif today <= rec.date_end and not rec.is_auto_renew:
else: rec.state = 'upcoming-close'
rec.state = 'closed' else:
rec.state = 'closed'
@api.depends( @api.depends(
'date_start', 'date_start',
@@ -202,13 +203,14 @@ class AccountAnalyticInvoiceLine(models.Model):
"""Date end should be auto-computed if a contract line is set to """Date end should be auto-computed if a contract line is set to
auto_renew""" auto_renew"""
for rec in self.filtered('is_auto_renew'): for rec in self.filtered('is_auto_renew'):
rec.date_end = ( if rec.date_start:
self.date_start rec.date_end = (
+ self.get_relative_delta( self.date_start
rec.auto_renew_rule_type, rec.auto_renew_interval + self.get_relative_delta(
rec.auto_renew_rule_type, rec.auto_renew_interval
)
- relativedelta(days=1)
) )
- relativedelta(days=1)
)
@api.onchange( @api.onchange(
'date_start', 'date_start',