【发布时间】:2018-05-03 07:17:25
【问题描述】:
我有搜索视图,我试图按产品('group_by':'product_id')过滤量化人员分组并按位置过滤('search_my_quants':1),但似乎量化人员仅按产品分组,而不是按地点。我不知道为什么。
搜索视图:
<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部分
<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部分
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)
如果我没有在搜索视图中使用group by filter,那么我有过滤位置。如何同时使用这两个过滤器?
已解决:
在搜索视图中,我更新了过滤器 productgroup,其中包含倾向于查找当前用户位置的域。
<filter string="Employee hardware" name="mano" context="{'group_by': 'product_id'}" domain="[('location_id.partner_id.user_ids.id', '=', uid)]"/>
【问题讨论】:
-
为什么不将搜索实现为真正的过滤器并将其称为默认值?
-
我用更多信息更新了我的问题并添加了搜索视图。除了 search_my_quants 之外,所有默认过滤器都是真正的过滤器。
-
这不是我的问题 :-P 我的意思是:为什么不将“我的量化”搜索作为搜索视图中的过滤器,并像其他默认搜索一样在菜单操作中调用它?
-
我认为你的
args.append中有一对括号太多了 -
因为我只是不知道该怎么做..
标签: xml python-2.7 odoo odoo-10 odoo-9