Skip to content

Commit

Permalink
[FW][FIX] sale: conflicting context content
Browse files Browse the repository at this point in the history
Most uses (correct ones) of the `partner` context key content expect a `res.partner` recordset as `partner` context value.
This value is extracted during the pricelist price computation (but not used anyway...).

But in one case, fixed by the current commit, a `res.partner` id is placed in the context, as `partner` value.  In some cases, this may trigger "Comparing Apple and Oranges" errors, since `with_context` calls returns a new or existing environment, verifying whether an environment with the same values (user, context, ...) exists.
During this comparison, the new context, with an id (int) as `partner` value, is compared with existing contexts, potentially including some with a recordset on the same key.  Such a comparison fails on the lowest `__eq__` level, raising "Comparing apples with oranges" error.

This commit fixes this case, by making sure the value put in the `partner` context value is always a recordset, and not an id.

closes odoo#78936

Note: In the future, this context key should be dropped because it's still a bad practice to put recordsets in the context.
Forward-port-of: odoo#78276
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
  • Loading branch information
royle-vietnam committed Oct 25, 2021
1 parent 3244944 commit 07677d5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion addons/sale/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _sale_get_invoice_price(self, order):

if self.product_id.expense_policy == 'sales_price':
product = self.product_id.with_context(
partner=order.partner_id.id,
partner=order.partner_id,
date_order=order.date_order,
pricelist=order.pricelist_id.id,
uom=self.product_uom_id.id,
Expand Down

0 comments on commit 07677d5

Please sign in to comment.