我想在边栏中创建一个菜单,显示特定类别的产品。我正在考虑为此任务使用过滤器,这是默认设置的。
但是,我不知道如何在我的 XML 域中使用我的配置值。
这是我的 XML 代码的样子:
<record id="my_product_search_form_view" model="ir.ui.view">
<field name="name">Products Of My Category Search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view" />
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<filter string="My Category" name="filter_my_categ" domain="[('categ_id','child_of',my_category)]"/>
</xpath>
</field>
</record>
<record id="my_product_action" model="ir.actions.act_window">
<field name="name">Products Of My Category</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{"search_default_filter_my_categ":1}</field>
<field name="search_view_id" ref="my_product_search_form_view" />
</record>
<menuitem id="menu_my_products" name="Products Of my Category"
parent="menu_product" action="my_product_action"
/>
我希望,当使用模型“product.template”将“my_category”添加到 ir.values 表时,该值将以某种方式添加到上下文中——但事实并非如此,我得到了一个 Odoo 客户端错误 NameError:名称“my_category”未定义
有谁知道如何在我的 XML View 中使用 ir.values 表的值 - 或者至少在 context
或 domain
标签中调用 python 方法?或者我的任务还有其他解决方案吗?感谢您的帮助!
最佳答案
我在 odoo v8 中试过了,它对我有用。
首先使用上下文创建没有域的过滤器。
<filter string="My Category" name="filter_my_categ" domain="[]" context="{'custom_filter':1}"/>
然后我继承了这样的搜索方法。
def search(self, cr, uid, args, offset=0, limit=None, order=None,context=None, count=False):
if context.get('custom_filter',False):
state = self.pool.get('ir.values').get_default(cr, uid, 'sale.order', 'dyn_filter')
args.append(['state','=',state])
result= super(sale_order_ext, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order,
context=context, count=count)
return result
就是这样。 谢谢。
关于python - Odoo 10 在 XML 中使用配置值(存储在 ir.values 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44880860/