Skip to Content
Menu
This question has been flagged
2 Replies
4205 Views

 odoo V12

I want filtered(domain) product_id  by warehouse_id in stock.picking 

I create warehouse_id field in product.prdouct and product.tempalte 


 class Produet(models.Model):

    _inherit='product.template'

    warehouse_id=fields.Many2one('stock.warehouse',string='warehouse')


class ProduetProduet(models.Model):

    _inherit='product.product'      warehouse_id=fields.Many2one('stock.warehouse',string='warehous',related='product_tmpl_id.warehouse_ids')


how can filter product_id by warehouse_id in stock_picking?

Avatar
Discard
Best Answer

Hi, Omer


By default in Odoo you can't add filters for related or computed fields. So in order to achieve that part you need to add "store=True" attribute inside the field like given below,

warehouse_id = fields.Many2one('stock.warehouse',string='Warehouse',related='product_tmpl_id.warehouse_ids', store=True)

And inside view file you can add filter and group by like below,

    <record id="inherit_product_template_search_view" model="ir.ui.view">
<field name="name">product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="warehouse_id" string="Warehouse"/>
<group string="Group BY">
<filter string="Warehouse" name="group_warehouse_id" context="{'group_by':'warehouse_id'}"/>
</group>
</field>
</field>
</record>

Other than this if you want then you don't need to add warehouse_id field inside the product, You can filter it by default by warehouse/location,

  • For this you need to follow below steps,

    • Got to the path, Inventory -> Configuration -> Warehouse Management -> Locations 

    • Then inside every location there is a button "Products" which helps to show products which belongs to that location. 

    •  https://prnt.sc/qwbgjc    

Feel free to ask in case you have any confusion related to the above point.


Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited


Avatar
Discard
Author Best Answer

Thanks Ashish Singh

I don't want to create a filter like you did

I want to filter products in the table to show only products  that has warehouse_id  , not all of them,

Avatar
Discard

Hi, Omer

In order to achieve this part "store=True" part is enough then you will be able to filter product by warehouse. Because by default in Odoo computed and related doesn't show inside filters.

For that part

"I want to filter products in the table to show only products that has warehouse_id , not all of them,"

you simply need to pass below line inside the product action,

<field name="domain">[('warehouse_id', '!=', False)]</field>

Feel free to ask in case you have any doubt related to the above point.

Thanks,