Skip to content

Commit

Permalink
[IMP] product_contract: Establish contract recurring interval in sale…
Browse files Browse the repository at this point in the history
… lines
  • Loading branch information
TelmoSuarez committed Sep 9, 2024
1 parent d17cd32 commit 6cca6c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
14 changes: 10 additions & 4 deletions product_contract/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions product_contract/tests/test_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
14 changes: 13 additions & 1 deletion product_contract/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,19 @@
attrs="{'invisible': [('is_contract', '=', False)]}"
/>
<group attrs="{'invisible': [('is_contract', '=', False)]}">
<field name="recurring_rule_type" />
<label for="recurring_rule_type" />
<div class="o_row">
<field
name="recurring_interval"
class="oe_inline"
nolabel="1"
/>
<field
name="recurring_rule_type"
class="oe_inline"
nolabel="1"
/>
</div>
</group>
<group attrs="{'invisible': [('is_contract', '=', False)]}">
<field name="recurring_invoicing_type" />
Expand Down

0 comments on commit 6cca6c6

Please sign in to comment.