Skip to content

Commit 2384f96

Browse files
committed
[IMP] product_contract: consider recurrence in SO lines amounts
Prior to f50e15d and the introduction of "sale.order.line.contract.mixin" the recurrence on a SO line used to be the quantity, thus the recurrence impacted the amounts of the line. Now that the recurrence is a separated field, we need to add it explicitly to the computation of the amounts.
1 parent a764a76 commit 2384f96

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

product_contract/models/sale_order_line.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,28 @@ def _get_contract_name_format(self):
278278
- Date: {date_text}
279279
"""
280280
)
281+
282+
def _prepare_base_line_for_taxes_computation(self, **kwargs):
283+
"""
284+
This is the base method for all line amounts computations.
285+
For 'is_contract' lines, we multiply the quantity by the recurrence.
286+
"""
287+
self.ensure_one()
288+
if self.is_contract:
289+
return self.env["account.tax"]._prepare_base_line_for_taxes_computation(
290+
self,
291+
**{
292+
"tax_ids": self.tax_id,
293+
"quantity": self.product_uom_qty * self.recurrence_number,
294+
"partner_id": self.order_id.partner_id,
295+
"currency_id": self.order_id.currency_id
296+
or self.order_id.company_id.currency_id,
297+
"rate": self.order_id.currency_rate,
298+
**kwargs,
299+
},
300+
)
301+
return super()._prepare_base_line_for_taxes_computation(**kwargs)
302+
303+
@api.depends("recurrence_number")
304+
def _compute_amount(self):
305+
return super()._compute_amount()

product_contract/tests/test_sale_order.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,26 @@ def test_order_line_date_start_confirm(self):
615615
sale.order_line.contract_id.contract_line_ids.date_start,
616616
fields.Date.to_date("2025-02-28"),
617617
)
618+
619+
def test_compute_amount(self):
620+
"""
621+
Check that recurrence is taken into account in line amounts.
622+
"""
623+
tax = self.env["account.tax"].create(
624+
{
625+
"name": "10% tax",
626+
"amount_type": "percent",
627+
"amount": 10,
628+
}
629+
)
630+
self.order_line1.update(
631+
{
632+
"price_unit": 100,
633+
"product_uom_qty": 10,
634+
"recurrence_number": 24,
635+
"tax_id": [(4, tax.id)],
636+
}
637+
)
638+
self.assertEqual(self.order_line1.price_subtotal, 24000)
639+
self.assertEqual(self.order_line1.price_tax, 2400)
640+
self.assertEqual(self.order_line1.price_total, 26400)

product_contract/views/sale_order.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
domain="[('contract_id','=',contract_id)]"
122122
optional="hide"
123123
/>
124-
<field name="recurrence_number" optional="hide" />
124+
<field name="recurrence_number" optional="show" />
125125
<field name="recurrence_interval" optional="hide" />
126126
<field name="recurring_interval" optional="hide" />
127127
<field name="recurring_rule_type" optional="hide" />

0 commit comments

Comments
 (0)