[IMP] contract: add next period start/end fields

Add two computed field showing the next period
start and end date. This improve the UX and will
enable further simplifications in the code.
This commit is contained in:
Stéphane Bidoul (ACSONE)
2019-12-06 11:09:32 +01:00
committed by Francisco Ivan Anton Prieto
parent 967023c31b
commit ea235974b8
2 changed files with 40 additions and 0 deletions

View File

@@ -41,6 +41,14 @@ class ContractLine(models.Model):
last_date_invoiced = fields.Date(
string='Last Date Invoiced', readonly=True, copy=False
)
next_period_date_start = fields.Date(
string='Next Period Start',
compute='_compute_next_period_date_start',
)
next_period_date_end = fields.Date(
string='Next Period End',
compute='_compute_next_period_date_end',
)
termination_notice_date = fields.Date(
string='Termination notice date',
compute="_compute_termination_notice_date",
@@ -389,6 +397,8 @@ class ContractLine(models.Model):
max_date_end,
):
"""Compute the end date for the next period"""
if not next_period_date_start:
return False
if max_date_end and next_period_date_start > max_date_end:
# start is past max date end: there is no next period
return False
@@ -412,6 +422,34 @@ class ContractLine(models.Model):
next_period_date_end = max_date_end
return next_period_date_end
@api.depends('last_date_invoiced', 'date_start', 'date_end')
def _compute_next_period_date_start(self):
for rec in self:
if rec.last_date_invoiced:
next_period_date_start = (
rec.last_date_invoiced + relativedelta(days=1)
)
else:
next_period_date_start = rec.date_start
if rec.date_end and next_period_date_start > rec.date_end:
next_period_date_start = False
rec.next_period_date_start = next_period_date_start
@api.depends(
'next_period_date_start',
'recurring_rule_type',
'recurring_interval',
'date_end',
)
def _compute_next_period_date_end(self):
for rec in self:
rec.next_period_date_end = self._get_next_period_date_end(
rec.next_period_date_start,
rec.recurring_rule_type,
rec.recurring_interval,
max_date_end=rec.date_end,
)
@api.model
def _get_first_date_end(
self, date_start, auto_renew_rule_type, auto_renew_interval

View File

@@ -15,11 +15,13 @@
<group>
<field name="create_invoice_visibility" invisible="1"/>
<field name="date_start" required="1"/>
<field name="next_period_date_start"/>
<field name="recurring_next_date"/>
</group>
<group>
<field name="date_end"
attrs="{'required': [('is_auto_renew', '=', True)]}"/>
<field name="next_period_date_end"/>
</group>
<group groups="base.group_no_one">
<field name="last_date_invoiced" readonly="True"/>