From d0dc4c60bdda38d4bbd537378e2d6c98675f34c8 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Tue, 26 Jun 2018 10:40:01 +0200 Subject: [PATCH] [FIX] purchase: dropshipping sequence in multi company Usecase to reproduce: - Create 2 sequence for PO(one for each company) - Create a product with dropshipping - Connect on the demo user with an active company different than the admin company - Create a SO for this product It will create a PO with the admin's company sequence. It happens because _run_buy use a sudo since SO user don't always have the purchase and inventory rights. However the company is not forced and thus the used company for sequence is the admin company. opw-1860802 --- addons/purchase/models/purchase.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 580a44da121..f27545a15ed 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -909,7 +909,8 @@ class ProcurementRule(models.Model): cache[domain] = po if not po: vals = self._prepare_purchase_order(product_id, product_qty, product_uom, origin, values, partner) - po = self.env['purchase.order'].sudo().create(vals) + company_id = values.get('company_id') and values['company_id'].id or self.env.user.company_id.id + po = self.env['purchase.order'].with_context(force_company=company_id).sudo().create(vals) cache[domain] = po elif not po.origin or origin not in po.origin.split(', '): if po.origin: