From 2010b05c324d6b55c201d43ec5926247db65d931 Mon Sep 17 00:00:00 2001 From: alvaro-domatix Date: Thu, 25 Jun 2026 18:24:01 +0000 Subject: [PATCH] [FIX] subscription_oca: recompute totals on line subtotal change _compute_total only depended on the list of lines (sale_subscription_line_ids), not on the lines' subtotals. As recurring_total/amount_tax/amount_total are stored, any later change to an existing line's price (pricelist change, manual unit price edit, discount update) recomputed the line subtotals but did not trigger the parent totals, leaving them stale. Depend on the aggregated line fields (price_subtotal, amount_tax_line_amount) so the subscription totals are refreshed whenever a line value changes. Covered by a regression test. --- subscription_oca/models/sale_subscription.py | 5 ++++- .../tests/test_subscription_oca.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/subscription_oca/models/sale_subscription.py b/subscription_oca/models/sale_subscription.py index b53cbe55b9..f22684ea8a 100644 --- a/subscription_oca/models/sale_subscription.py +++ b/subscription_oca/models/sale_subscription.py @@ -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 diff --git a/subscription_oca/tests/test_subscription_oca.py b/subscription_oca/tests/test_subscription_oca.py index 29d301ee1f..b09b3089ad 100644 --- a/subscription_oca/tests/test_subscription_oca.py +++ b/subscription_oca/tests/test_subscription_oca.py @@ -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)