[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
This commit is contained in:
Prakash Prajapati
2018-05-07 15:41:31 +02:00
committed by Goffin Simon
parent 9da8378a0a
commit 7c7b099273
+5 -2
View File
@@ -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)],