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)