diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py
index 70210cec12..3cf8bcb4eb 100644
--- a/contract/models/abstract_contract.py
+++ b/contract/models/abstract_contract.py
@@ -80,3 +80,20 @@ def _compute_journal_id(self):
contract.journal_id = journal.id
else:
contract.journal_id = None
+
+ @api.onchange(
+ "date_start",
+ "date_end",
+ "recurring_interval",
+ "recurring_rule_type",
+ "recurring_invoicing_type",
+ )
+ def _onchange_recurrency_fields(self):
+ if self.contract_line_fixed_ids:
+ self.contract_line_fixed_ids.date_start = self.date_start
+ self.contract_line_fixed_ids.date_end = self.date_end
+ self.contract_line_fixed_ids.recurring_interval = self.recurring_interval
+ self.contract_line_fixed_ids.recurring_rule_type = self.recurring_rule_type
+ self.contract_line_fixed_ids.recurring_invoicing_type = (
+ self.recurring_invoicing_type
+ )
diff --git a/contract/models/abstract_contract_line.py b/contract/models/abstract_contract_line.py
index 5c07da6f56..fdd6e64522 100644
--- a/contract/models/abstract_contract_line.py
+++ b/contract/models/abstract_contract_line.py
@@ -85,6 +85,12 @@ class ContractAbstractContractLine(models.AbstractModel):
readonly=False,
copy=True,
)
+ date_end = fields.Date(
+ compute="_compute_date_end",
+ store=True,
+ readonly=False,
+ copy=True,
+ )
last_date_invoiced = fields.Date()
is_canceled = fields.Boolean(string="Canceled", default=False)
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
@@ -166,11 +172,9 @@ def _compute_recurring_interval(self):
def _compute_date_start(self):
self._set_recurrence_field("date_start")
- # pylint: disable=missing-return
- @api.depends("contract_id.recurring_next_date", "contract_id.line_recurrence")
- def _compute_recurring_next_date(self):
- super()._compute_recurring_next_date()
- self._set_recurrence_field("recurring_next_date")
+ @api.depends("contract_id.date_end", "contract_id.line_recurrence")
+ def _compute_date_end(self):
+ self._set_recurrence_field("date_end")
@api.depends("display_type", "note_invoicing_mode")
def _compute_is_recurring_note(self):
diff --git a/contract/models/contract.py b/contract/models/contract.py
index 5b2b0ab596..ac4caa923d 100644
--- a/contract/models/contract.py
+++ b/contract/models/contract.py
@@ -80,7 +80,6 @@ class ContractContract(models.Model):
create_invoice_visibility = fields.Boolean(
compute="_compute_create_invoice_visibility"
)
- date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
payment_term_id = fields.Many2one(
comodel_name="account.payment.term", string="Payment Terms", index=True
)
@@ -302,14 +301,6 @@ def action_show_invoices(self):
action["views"] = [(tree_view.id, "tree"), (form_view.id, "form")]
return action
- @api.depends("contract_line_ids.date_end")
- def _compute_date_end(self):
- for contract in self:
- contract.date_end = False
- date_end = contract.contract_line_ids.mapped("date_end")
- if date_end and all(date_end):
- contract.date_end = max(date_end)
-
@api.depends(
"contract_line_ids.recurring_next_date",
"contract_line_ids.is_canceled",
diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py
index aa3c6f7440..3567ad82db 100644
--- a/contract/models/contract_line.py
+++ b/contract/models/contract_line.py
@@ -34,7 +34,6 @@ class ContractLine(models.Model):
)
currency_id = fields.Many2one(related="contract_id.currency_id")
date_start = fields.Date(required=True)
- date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
termination_notice_date = fields.Date(
compute="_compute_termination_notice_date",
store=True,
@@ -100,36 +99,6 @@ class ContractLine(models.Model):
readonly=True,
)
- @api.depends(
- "last_date_invoiced",
- "date_start",
- "date_end",
- "contract_id.last_date_invoiced",
- "contract_id.contract_line_ids.last_date_invoiced",
- )
- # pylint: disable=missing-return
- def _compute_next_period_date_start(self):
- """Rectify next period date start if another line in the contract has been
- already invoiced previously when the recurrence is by contract.
- """
- rest = self.filtered(lambda x: x.contract_id.line_recurrence)
- for rec in self - rest:
- lines = rec.contract_id.contract_line_ids
- if not rec.last_date_invoiced and any(lines.mapped("last_date_invoiced")):
- next_period_date_start = max(
- lines.filtered("last_date_invoiced").mapped("last_date_invoiced")
- ) + relativedelta(days=1)
- 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
- else:
- rest |= rec
- super(ContractLine, rest)._compute_next_period_date_start()
-
- @api.depends("contract_id.date_end", "contract_id.line_recurrence")
- def _compute_date_end(self):
- self._set_recurrence_field("date_end")
-
@api.depends(
"date_end",
"termination_notice_rule_type",
diff --git a/contract/models/contract_recurrency_mixin.py b/contract/models/contract_recurrency_mixin.py
index aebc76c3f2..6cc732d352 100644
--- a/contract/models/contract_recurrency_mixin.py
+++ b/contract/models/contract_recurrency_mixin.py
@@ -48,6 +48,7 @@ class ContractRecurrencyBasicMixin(models.AbstractModel):
help="Invoice every (Days/Week/Month/Year)",
)
date_start = fields.Date()
+ date_end = fields.Date()
recurring_next_date = fields.Date(string="Date of Next Invoice")
@api.depends("recurring_invoicing_type", "recurring_rule_type")
@@ -78,7 +79,10 @@ class ContractRecurrencyMixin(models.AbstractModel):
date_start = fields.Date(default=lambda self: fields.Date.context_today(self))
recurring_next_date = fields.Date(
- compute="_compute_recurring_next_date", store=True, readonly=False, copy=True
+ compute="_compute_recurring_next_date",
+ store=True,
+ readonly=False,
+ copy=True,
)
date_end = fields.Date(index=True)
next_period_date_start = fields.Date(
diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py
index 8f756b4f2b..888c413d9d 100644
--- a/contract/tests/test_contract.py
+++ b/contract/tests/test_contract.py
@@ -251,6 +251,7 @@ def test_automatic_price(self):
self.assertEqual(self.acct_line.price_unit, 10)
def test_contract(self):
+ self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-01-15"))
self.assertEqual(self.contract.recurring_next_date, to_date("2018-01-15"))
self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0)
self.acct_line.price_unit = 100.0
diff --git a/contract/views/contract.xml b/contract/views/contract.xml
index 5c5c959aee..1dea979301 100644
--- a/contract/views/contract.xml
+++ b/contract/views/contract.xml
@@ -254,6 +254,11 @@
name="last_date_invoiced"
groups="base.group_no_one"
/>
+
+