I have search view where I am trying to filter quants grouping by product ('group_by': 'product_id') and filter by location ('search_my_quants': 1) but it seems quants are grouping only by product and not filtered by location. I have no idea why.
search view:
<record id="view_stock_quant_search" model="ir.ui.view">
<field name="name">stock.quant.search</field>
<field name="model">stock.quant</field>
<field eval="1" name="priority"/>
<field name="arch" type="xml">
<search string="Quants">
<field name="location_id"/>
<field name="product_id"/>
<field name="lot_id" />
<group expand='0' string='Filters'>
<filter name="work_hardware" string="Hardware" domain="[('product_id.attribute', '=', 'work_hardware')]"/>
<filter name="hide_reserved" string="Hide Reserved" domain="[('reservation_id', '=', False)]"/>
</group>
<group expand='0' string='Group by...'>
<filter string='Product' name="productgroup" context="{'group_by': 'product_id'}"/>
</group>
</search>
</field>
</record>
xml part
<record model="ir.actions.act_window" id="action_stock_quant_my">
<field name="name">Mine</field>
<field name="res_model">stock.quant</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_stock_quant_tree"/>
<field name="search_view_id" ref="view_stock_quant_search"/>
<field name="context">{'group_by': 'product_id', 'search_my_quants': 1, 'search_default_hide_reserved': 1, 'search_default_work_hardware':1}</field>
</record>
python part
class stock_quant(models.Model):
_inherit = "stock.quant"
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
context = self.env.context or {}
if context.get('search_my_quants'):
args.append(('location_id.partner_id.id', '=', self.env.user.partner_id.id))
return super(stock_quant, self).search(args, offset, limit, order, count=count)
If I am not using group by filter
in search view then I have filtering location. How can I use both filters together?
SOLVED:
On search view I updated filter productgroup with domain which tend to find current user's location.
<filter string="Employee hardware" name="mano" context="{'group_by': 'product_id'}" domain="[('location_id.partner_id.user_ids.id', '=', uid)]"/>
args.append
– CZoellner