From 7c7b0992734ded9e72a04e4a412582763cff9a79 Mon Sep 17 00:00:00 2001 From: Prakash Prajapati Date: Wed, 21 Feb 2018 18:42:59 +0530 Subject: [PATCH] [FIX] stock: Quantity available according to the warehouse or location The goal of this change is not to be able to search a location_id/warehouse_id but to properly make these fields "dummy": only used to put some keys in context from the search view in order to influence computed field. Use case: In function _compute_quantities_dict, the quantity available for a product is computed according to the warehouse or the location. But to compute this quantity, the specific warehouse or location must be in the context. Steps to reproduce: - In the tree view of product.product, write the name of a warehouse W - Click on dropdown menu "Search warehouse" - Click on W Expected behavior: the quantities available for W are displayed. NB: search=lambda operator, operand, vals: [] must be written to ensure these fields to be searchable. Otherwise "Non-stored field product.template.warehouse_id cannot be searched." was logged. opw:1839961 --- addons/stock/models/product.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index c8e5dd8e2ca..97b437b4c5a 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -412,8 +412,11 @@ class ProductTemplate(models.Model): outgoing_qty = fields.Float( 'Outgoing', compute='_compute_quantities', search='_search_outgoing_qty', digits=dp.get_precision('Product Unit of Measure')) - location_id = fields.Many2one('stock.location', 'Location') - warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse') + # The goal of these fields is not to be able to search a location_id/warehouse_id but + # to properly make these fields "dummy": only used to put some keys in context from + # the search view in order to influence computed field + location_id = fields.Many2one('stock.location', 'Location', store=False, search=lambda operator, operand, vals: []) + warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse', store=False, search=lambda operator, operand, vals: []) route_ids = fields.Many2many( 'stock.location.route', 'stock_route_product', 'product_id', 'route_id', 'Routes', domain=[('product_selectable', '=', True)],