From 6ce265b8152d96f8dd49b8ceeac736b8143c4f3c Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 17 Sep 2018 14:17:29 +0200 Subject: [PATCH] [FIX] sale_stock: translate product name Use case: have a partner in fr_FR while operating with a user in en_US Create a SO for that partner add a product which name is translated in french Before this commit, the description of the sale order line takes the *untranslated* name of the product After this commit, it takes the *translated* name of the product The issue was due to a limitation of sudoing within an onchange for related fields (typically the case of product.product.name) In this case, values that are missing in the cache are retrieved from another one In our case: First, _onchange_product_id_check_availability triggers the evaluation of product.name as sudo (later in the stack), without lang in context Second, the function that actually uses the product.name (product_id_change) retrieves the value found before from the 'wrong' cache OPW 1863305, 1884106 closes #27031 --- addons/sale_stock/models/sale_order.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 3917e2782de..486c022d14c 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -163,7 +163,10 @@ class SaleOrderLine(models.Model): return {} if self.product_id.type == 'product': precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') - product = self.product_id.with_context(warehouse=self.order_id.warehouse_id.id) + product = self.product_id.with_context( + warehouse=self.order_id.warehouse_id.id, + lang=self.order_id.partner_id.lang or self.env.user.lang or 'en_US' + ) product_qty = self.product_uom._compute_quantity(self.product_uom_qty, self.product_id.uom_id) if float_compare(product.virtual_available, product_qty, precision_digits=precision) == -1: is_available = self._check_routing()