Skip to content

Commit

Permalink
[FIX] sale_management: dispense temp cache records
Browse files Browse the repository at this point in the history
**Current behavior:**
If a recurring sale order has an associated sale order option
and the recurring plan of the order is changed, a trace back
occurs.

**Expected behavior:**
The recurring plan can be changed as it ordinarily would.

**Steps to reproduce:**
1. Add a recurring product to a sale order

2. Add an optional recurring product to the order

3. Try to change the recurring plan of the order to encounter
     the trace back

**Cause of the issue:**
This flow causes some 'phantom' sale order lines to have their
price recalculated (phantom because they have no price, qty,
currency, nor order_id field values). During this recalculation
a currency_id is expected either in the line itself or in the
sale order it is a part of. Because there is no value for either
of these, it fails the ensure_one() method in the sequence
(0 vals, expects 1).

The phantom lines are created in the `sale.order.option` model
in the `sale_management` module, in `_compute_price_unit()` and
`_compute_discount()`.

**Fix:**
Call `invalidate_recorset(flush=False)` on these cached records
at the end of the methods in which they are created.

opw-3754297

closes odoo#157515

Related: odoo/enterprise#58264
Signed-off-by: Vincent Ethan <etvi@odoo.com>
  • Loading branch information
ethanrobv committed Mar 22, 2024
1 parent 3a61e14 commit 16f51c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions addons/sale_management/models/sale_order_option.py
Expand Up @@ -89,8 +89,8 @@ def _compute_price_unit(self):
new_sol = self.env['sale.order.line'].new(values)
new_sol._compute_price_unit()
option.price_unit = new_sol.price_unit
# Avoid attaching the new line when called on template change
new_sol.order_id = False
# Drop the temporary record from the cache
new_sol.invalidate_recordset(flush=False)

@api.depends('product_id', 'uom_id', 'quantity')
def _compute_discount(self):
Expand All @@ -102,8 +102,8 @@ def _compute_discount(self):
new_sol = self.env['sale.order.line'].new(values)
new_sol._compute_discount()
option.discount = new_sol.discount
# Avoid attaching the new line when called on template change
new_sol.order_id = False
# Drop the temporary record from the cache
new_sol.invalidate_recordset(flush=False)

def _get_values_to_add_to_order(self):
self.ensure_one()
Expand Down

0 comments on commit 16f51c9

Please sign in to comment.