Browse Source

[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.
pull/434/head
Stéphane Bidoul (ACSONE) 5 years ago
parent
commit
edf6833bec
No known key found for this signature in database GPG Key ID: BCAB2555446B5B92
  1. 38
      contract/models/contract_line.py
  2. 2
      contract/views/contract_line.xml

38
contract/models/contract_line.py

@ -41,6 +41,14 @@ class ContractLine(models.Model):
last_date_invoiced = fields.Date( last_date_invoiced = fields.Date(
string='Last Date Invoiced', readonly=True, copy=False 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( termination_notice_date = fields.Date(
string='Termination notice date', string='Termination notice date',
compute="_compute_termination_notice_date", compute="_compute_termination_notice_date",
@ -389,6 +397,8 @@ class ContractLine(models.Model):
max_date_end, max_date_end,
): ):
"""Compute the end date for the next period""" """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: if max_date_end and next_period_date_start > max_date_end:
# start is past max date end: there is no next period # start is past max date end: there is no next period
return False return False
@ -412,6 +422,34 @@ class ContractLine(models.Model):
next_period_date_end = max_date_end next_period_date_end = max_date_end
return next_period_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 @api.model
def _get_first_date_end( def _get_first_date_end(
self, date_start, auto_renew_rule_type, auto_renew_interval self, date_start, auto_renew_rule_type, auto_renew_interval

2
contract/views/contract_line.xml

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

Loading…
Cancel
Save