Skip to content

Commit

Permalink
[FIX] product_supplierinfo_for_customer_sale: Don't inject context in…
Browse files Browse the repository at this point in the history
… onchange

The previous code was trying to avoid a double search on customerinfo
passing by context the already searched customerinfo, but the ORM makes
some artifacts (like duplicating one2many references with NewId records)
on that cases, provoking the call chain to fail when comparing .id on
NewId.

The solution is to not pass anything by context and do the search 2
times. Anyway, the performance improvement was low, having data in
cache.

TT49073
  • Loading branch information
pedrobaeza authored and victoralmau committed May 31, 2024
1 parent 1360c04 commit 9e6d426
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions product_supplierinfo_for_customer_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ def _update_description(self):
This also takes from context the possible customerinfo already searched in
product_id_change for avoiding duplicated searches.
"""
if "customerinfo" in self.env.context:
customerinfo = self.env.context["customerinfo"]
else:
customerinfo = self.product_id._select_customerinfo(
partner=self.order_partner_id
)
# We need to repeat the search here, as passing the value by context or any
# other trick makes the ORM to do ugly things in "onchange" mode
customerinfo = self.product_id._select_customerinfo(
partner=self.order_partner_id
)
if customerinfo.product_code:
# Avoid to put the standard internal reference
self = self.with_context(display_default_code=False)
Expand All @@ -52,15 +51,12 @@ def _onchange_product_id_warning(self):
"""Inject the customerinfo in the context for not repeating the search in
_update_description + assign the mininum quantity if set.
"""
res = super()._onchange_product_id_warning()
for line in self:
customerinfo = self.env["product.customerinfo"]
if line.product_id:
customerinfo = line.product_id._select_customerinfo(
partner=line.order_partner_id
)
super(
SaleOrderLine, line.with_context(customerinfo=customerinfo)
)._onchange_product_id_warning()
if customerinfo and customerinfo.min_qty:
line.product_uom_qty = customerinfo.min_qty
return {}
if customerinfo.min_qty:
line.product_uom_qty = customerinfo.min_qty
return res

0 comments on commit 9e6d426

Please sign in to comment.