From ddfae4b7600af1c491a255b4d277dfc637023d60 Mon Sep 17 00:00:00 2001 From: "David (dafr)" Date: Wed, 7 Sep 2022 08:53:49 +0000 Subject: [PATCH] [FIX] purchase_stock: get ID of buy_route only if it exists # How to reproduce: - Delete external ID "purchase_stock.route_warehouse0_buy" - Try to create a Product "purchase_stock.route_warehouse0_buy" was meant to be optional. We can only get the id after checking that it exist. OPW-2972494 closes odoo/odoo#102872 X-original-commit: 1b7b4cdbee07c325753c1b9362414e8309ef8718 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: DavidFesquet --- addons/purchase_stock/models/product.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index 6aca371a506..55b055333eb 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -11,10 +11,9 @@ class ProductTemplate(models.Model): @api.model def _get_buy_route(self): - 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)]) + buy_route = self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False) if buy_route: - return buy_route.ids + return self.env['stock.route'].search([('id', '=', buy_route.id)]).ids return [] route_ids = fields.Many2many(default=lambda self: self._get_buy_route())