Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ def cron_subscription_management(self):
subscription.action_start_subscription()
subscription.generate_invoice()

@api.depends("sale_subscription_line_ids")
@api.depends(
"sale_subscription_line_ids.price_subtotal",
"sale_subscription_line_ids.amount_tax_line_amount",
)
def _compute_total(self):
for record in self:
recurring_total = amount_tax = 0.0
Expand Down
18 changes: 18 additions & 0 deletions subscription_oca/tests/test_subscription_oca.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,21 @@ def test_manual_discount_persistence(self):
10.0,
"Manual discount was lost after changing the quantity (Bug #1320)",
)

def test_recurring_total_recomputes_on_line_price_change(self):
"""Changing the unit price of an existing line must refresh the stored
subscription totals. Regression: ``_compute_total`` only depended on the
list of lines, so any later edit to a line's price (pricelist change,
manual edit, discount) left ``recurring_total`` stale."""
subscription = self.create_sub({})
line = self.create_sub_line(subscription)
subscription.flush_recordset()
before = subscription.recurring_total
# Edit the unit price of the already existing line.
line.price_unit = 1234.0
self.assertEqual(
subscription.recurring_total,
line.price_subtotal,
"Totals were not refreshed after a line price change.",
)
self.assertNotEqual(before, subscription.recurring_total)
Loading