From 051395275a62aab311a725dc6b91ee557c4afedc Mon Sep 17 00:00:00 2001 From: brian10048 Date: Fri, 27 Dec 2019 15:08:59 -0500 Subject: [PATCH] [12.0] [IMP] product_contract Add recurring interval to product and sale lines in order to allow intervals other than 1 --- product_contract/models/contract_line.py | 2 +- product_contract/models/product_template.py | 6 ++++++ product_contract/models/sale_order_line.py | 21 ++++++++++++++++----- product_contract/views/product_template.xml | 8 +++++++- product_contract/views/sale_order.xml | 8 +++++++- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index 2a85f73e..baf99787 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -44,7 +44,7 @@ class ContractLine(models.Model): rec.recurring_invoicing_type = ( rec.product_id.recurring_invoicing_type ) - rec.recurring_interval = 1 + rec.recurring_interval = rec.product_id.recurring_interval rec.is_auto_renew = rec.product_id.is_auto_renew rec.auto_renew_interval = rec.product_id.default_qty rec.auto_renew_rule_type = rec._get_auto_renew_rule_type() diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index 1ca3f75e..0ae8f4e7 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -26,6 +26,12 @@ class ProductTemplate(models.Model): string='Invoice Every', help="Specify Interval for automatic invoice generation.", ) + recurring_interval = fields.Integer( + default=1, + string='Invoice Every', + help="Invoice every (Days/Week/Month/Year)", + required=True, + ) recurring_invoicing_type = fields.Selection( [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')], default='pre-paid', diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 6f55f5c4..b5bde56f 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -34,6 +34,12 @@ class SaleOrderLine(models.Model): string='Invoice Every', copy=False, ) + recurring_interval = fields.Integer( + default=1, + string='Invoice Every', + help="Invoice every (Days/Week/Month/Year)", + required=True, + ) recurring_invoicing_type = fields.Selection( [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')], default='pre-paid', @@ -75,12 +81,17 @@ class SaleOrderLine(models.Model): rec.date_start + contract_line_model.get_relative_delta( rec._get_auto_renew_rule_type(), - int(rec.product_uom_qty), + int(rec.product_uom_qty*rec.recurring_interval), ) - relativedelta(days=1) ) - @api.onchange('date_start', 'product_uom_qty', 'recurring_rule_type') + @api.onchange( + 'date_start', + 'product_uom_qty', + 'recurring_rule_type', + 'recurring_interval' + ) def onchange_date_start(self): contract_line_model = self.env['contract.line'] for rec in self.filtered('product_id.is_contract'): @@ -91,7 +102,7 @@ class SaleOrderLine(models.Model): rec.date_start + contract_line_model.get_relative_delta( rec._get_auto_renew_rule_type(), - int(rec.product_uom_qty), + int(rec.product_uom_qty*rec.recurring_interval), ) - relativedelta(days=1) ) @@ -112,7 +123,7 @@ class SaleOrderLine(models.Model): 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 @@ -143,7 +154,7 @@ class SaleOrderLine(models.Model): '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.product_id.is_auto_renew, diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml index 057ec95b..9c150210 100644 --- a/product_contract/views/product_template.xml +++ b/product_contract/views/product_template.xml @@ -29,7 +29,13 @@ - + diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index 4fd1b90b..551e8667 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -55,7 +55,13 @@ attrs="{'invisible': [('is_contract', '=', False)]}"/> - +