From 90569e55abdee3f0a65d8e2be50fb901945a8221 Mon Sep 17 00:00:00 2001 From: "Merlin (megu)" Date: Wed, 13 Apr 2022 14:16:27 +0000 Subject: [PATCH] [FIX] purchase_stock: use a valid route as default buy route In a multi-company environment, creating a product template will always try to assign it's route to `route_warehouse0_buy` but this throws an error if the current company is not the one of the route Steps to reproduce: 1. Install Inventory and Purchase 2. Go to Settings > Inventory > Warehouse and enable Multi-Step Routes 3. Open Inventory and go to Configuration > Warehouse Management > Routes 4. Open the 'Buy' route, assign it to one of the company for example 'My Company (San Fransisco)' and save 5. Go to Products and select an other company for example 'My Company (Chicago)' 6. Click on `CREATE` 7. An error is thrown, preventing the user from creating new products Problem: Function `_get_buy_route` always fetched the same route but this route's company might have been changed so an error is thrown when trying to access it from the other company Solution: Check if we have access to `route_warehouse0_buy` before using it. opw-2805154 closes odoo/odoo#90093 X-original-commit: 1a733ae0bfd9f1cb1e90a2cab80af290560c6f12 Signed-off-by: Arnold Moyaux Signed-off-by: Guillaume Merlin (megu) --- addons/purchase_stock/models/product.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index 4ae5dc799a1..a31566db243 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -11,7 +11,8 @@ class ProductTemplate(models.Model): @api.model def _get_buy_route(self): - buy_route = self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False) + buy_route_id = self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False).id + buy_route = self.env['stock.route'].search([('id', '=', buy_route_id)]) if buy_route: return buy_route.ids return []