From 6cca6c6804dbd817d83875a7601a4bca93e791af Mon Sep 17 00:00:00 2001 From: Telmo Suarez Date: Thu, 5 Sep 2024 15:13:19 +0200 Subject: [PATCH] [IMP] product_contract: Establish contract recurring interval in sale lines --- product_contract/models/sale_order_line.py | 14 ++++++++++---- product_contract/tests/test_sale_order.py | 8 ++++++-- product_contract/views/sale_order.xml | 14 +++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 4d2ec0091f..776574ad69 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -43,6 +43,12 @@ class SaleOrderLine(models.Model): help="Specify if process date is 'from' or 'to' invoicing date", copy=False, ) + recurring_interval = fields.Integer( + string="Invoice Every", + default=1, + help="Invoice every (Days/Week/Month/Year)", + copy=False, + ) date_start = fields.Date() date_end = fields.Date() @@ -114,7 +120,7 @@ def _get_date_end(self): self.date_start + contract_line_model.get_relative_delta( self._get_auto_renew_rule_type(), - int(self.product_uom_qty), + int(self.recurring_interval), ) - relativedelta(days=1) ) @@ -124,7 +130,7 @@ def _get_date_end(self): def _compute_auto_renew(self): for rec in self: if rec.product_id.is_contract: - rec.product_uom_qty = rec.product_id.default_qty + rec.recurring_interval = rec.product_id.default_qty rec.recurring_rule_type = rec.product_id.recurring_rule_type rec.recurring_invoicing_type = rec.product_id.recurring_invoicing_type rec.date_start = rec.date_start or fields.Date.today() @@ -164,7 +170,7 @@ def _prepare_contract_line_values( self.date_start or fields.Date.today(), self.recurring_invoicing_type, self.recurring_rule_type, - 1, + self.recurring_interval, ) termination_notice_interval = self.product_id.termination_notice_interval termination_notice_rule_type = self.product_id.termination_notice_rule_type @@ -179,7 +185,7 @@ def _prepare_contract_line_values( "date_end": self.date_end, "date_start": self.date_start or fields.Date.today(), "recurring_next_date": recurring_next_date, - "recurring_interval": 1, + "recurring_interval": self.recurring_interval, "recurring_invoicing_type": self.recurring_invoicing_type, "recurring_rule_type": self.recurring_rule_type, "is_auto_renew": self.is_auto_renew, diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index d315179ba4..ce7c2d1294 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -117,7 +117,7 @@ def test_action_confirm(self): contract_line = self.order_line1.contract_id.contract_line_ids self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01")) self.assertEqual(contract_line.date_end, Date.to_date("2018-12-31")) - self.assertEqual(contract_line.recurring_next_date, Date.to_date("2018-01-31")) + self.assertEqual(contract_line.recurring_next_date, Date.to_date("2018-12-31")) def test_change_sale_company(self): self.assertTrue(self.sale.company_id) @@ -166,7 +166,7 @@ def test_action_confirm_without_contract_creation(self): contract_line = self.order_line1.contract_id.contract_line_ids self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01")) self.assertEqual(contract_line.date_end, Date.to_date("2018-12-31")) - self.assertEqual(contract_line.recurring_next_date, Date.to_date("2018-01-31")) + self.assertEqual(contract_line.recurring_next_date, Date.to_date("2018-12-31")) def test_sale_contract_count(self): """It should count contracts as many different contract template used @@ -187,6 +187,10 @@ def test_onchange_product(self): self.order_line1.recurring_invoicing_type, self.product1.recurring_invoicing_type, ) + self.assertEqual( + self.order_line1.recurring_interval, + self.product1.default_qty, + ) self.assertEqual(self.order_line1.date_end, Date.to_date("2018-12-31")) def test_check_contract_sale_partner(self): diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index a5913e0cb0..9cc595958e 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -62,7 +62,19 @@ attrs="{'invisible': [('is_contract', '=', False)]}" /> - +