[FIX] stock: do not display 'Location' and 'Warehouse' in search view

- Go to Inventory > Reporting > Inventory Valuation
- Run the report
- In the search view, filter on 'Location' or 'Warehouse'

The filter doesn't work.

Actually, the filter can't work. This is a hack introduced in order to
add context keys.

Originally, the function `search` was added to avoid the error log
'Non-stored field %s cannot be searched.'. This happens because the web
client adds the field in the domain on top of adding the context key. By
using `filter_domain`, no domain is added and no error is logged.

opw-2075456

closes odoo/odoo#37347

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-09-24 10:32:41 +00:00
parent a7a60f7c61
commit a5835a160e
2 changed files with 6 additions and 7 deletions
+4 -5
View File
@@ -490,11 +490,10 @@ class ProductTemplate(models.Model):
outgoing_qty = fields.Float(
'Outgoing', compute='_compute_quantities', search='_search_outgoing_qty',
digits=dp.get_precision('Product Unit of Measure'))
# 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: [])
# The goal of these fields is to be able to put some keys in context from search view in order
# to influence computed field.
location_id = fields.Many2one('stock.location', 'Location', store=False)
warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse', store=False)
route_ids = fields.Many2many(
'stock.location.route', 'stock_route_product', 'product_id', 'route_id', 'Routes',
domain=[('product_selectable', '=', True)],
+2 -2
View File
@@ -73,8 +73,8 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='pricelist_id']" position="after">
<separator/>
<field name="location_id" context="{'location': self}"/>
<field name="warehouse_id" context="{'warehouse': self}"/>
<field name="location_id" context="{'location': self}" filter_domain="[]"/>
<field name="warehouse_id" context="{'warehouse': self}" filter_domain="[]"/>
<separator/>
<filter name="real_stock_available" string="Available Products" domain="[('qty_available','&gt;',0)]"/>
<filter name="real_stock_negative" string="Negative Forecasted Quantity" domain="[('virtual_available','&lt;',0)]"/>