From eebb8e1484f29f4ae54617b1043d38f0cc1dd32f Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 28 Aug 2019 08:33:54 +0000 Subject: [PATCH] [FIX] *: remove buggy calls to with_context When .with_context() is called with a dictionary as 1st positional argument, it will replace context (and not modify the referenced keys) It may create bugs when losing the content of the context (e.g. remove partner's language) This is a cherry-pick to saas-12.5 of odoo/odoo#36164 of the logistic part as discussed closes odoo/odoo#36690 Signed-off-by: Martin Trigaux (mat) --- addons/purchase_requisition/models/purchase.py | 8 ++++---- addons/purchase_stock/models/stock_rule.py | 8 ++++---- addons/sale_purchase/models/sale_order.py | 8 ++++---- addons/stock/models/product.py | 2 +- addons/stock/models/stock_location.py | 2 +- addons/stock/wizard/stock_backorder_confirmation.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/purchase_requisition/models/purchase.py b/addons/purchase_requisition/models/purchase.py index 694f2df18f6..360c7633ff6 100644 --- a/addons/purchase_requisition/models/purchase.py +++ b/addons/purchase_requisition/models/purchase.py @@ -47,10 +47,10 @@ class PurchaseOrder(models.Model): order_lines = [] for line in requisition.line_ids: # Compute name - product_lang = line.product_id.with_context({ - 'lang': partner.lang, - 'partner_id': partner.id, - }) + product_lang = line.product_id.with_context( + lang=partner.lang, + partner_id=partner.id + ) name = product_lang.display_name if product_lang.description_purchase: name += '\n' + product_lang.description_purchase diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index e52ba572c35..c23e5dee1b0 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -221,10 +221,10 @@ class StockRule(models.Model): price_unit = seller.currency_id._convert( price_unit, po.currency_id, po.company_id, po.date_order or fields.Date.today()) - product_lang = product_id.with_context({ - 'lang': partner.lang, - 'partner_id': partner.id, - }) + product_lang = product_id.with_context( + lang=partner.lang, + partner_id=partner.id, + ) name = product_lang.display_name if product_lang.description_purchase: name += '\n' + product_lang.description_purchase diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index 76571c56557..5ad2d3e6c99 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -225,10 +225,10 @@ class SaleOrderLine(models.Model): price_unit = supplierinfo.currency_id.compute(price_unit, purchase_order.currency_id) # purchase line description in supplier lang - product_in_supplier_lang = self.product_id.with_context({ - 'lang': supplierinfo.name.lang, - 'partner_id': supplierinfo.name.id, - }) + product_in_supplier_lang = self.product_id.with_context( + lang=supplierinfo.name.lang, + partner_id=supplierinfo.name.id, + ) name = '[%s] %s' % (self.product_id.default_code, product_in_supplier_lang.display_name) if product_in_supplier_lang.description_purchase: name += '\n' + product_in_supplier_lang.description_purchase diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index b777c263a66..a3f7c716207 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -507,7 +507,7 @@ class Product(models.Model): return self.env['stock.quant'].with_context(ctx)._get_quants_action(domain) def action_update_quantity_on_hand(self): - return self.product_tmpl_id.with_context({'default_product_id': self.id}).action_update_quantity_on_hand() + return self.product_tmpl_id.with_context(default_product_id=self.id).action_update_quantity_on_hand() def action_product_forecast_report(self): action = self.env.ref('stock.report_stock_quantity_action_product').read()[0] diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index c5e08556a9b..ec304508e5c 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -118,7 +118,7 @@ class Location(models.Model): raise UserError(_('You still have some product in locations %s') % (','.join(children_quants.mapped('location_id.name')))) else: - super(Location, children_location - self).with_context({'do_not_check_quant': True}).write(values) + super(Location, children_location - self).with_context(do_not_check_quant=True).write(values) return super(Location, self).write(values) @api.model diff --git a/addons/stock/wizard/stock_backorder_confirmation.py b/addons/stock/wizard/stock_backorder_confirmation.py index 5c8fc2a43c4..6884d2ebddf 100644 --- a/addons/stock/wizard/stock_backorder_confirmation.py +++ b/addons/stock/wizard/stock_backorder_confirmation.py @@ -22,7 +22,7 @@ class StockBackorderConfirmation(models.TransientModel): precision_rounding=move.product_uom.rounding) > 0: moves_to_log[move] = (move.quantity_done, move.product_uom_qty) pick_id._log_less_quantities_than_expected(moves_to_log) - confirmation.pick_ids.with_context({'cancel_backorder': cancel_backorder}).action_done() + confirmation.pick_ids.with_context(cancel_backorder=cancel_backorder).action_done() def process(self): self._process()