Python Odoo 10在XML中使用配置值(存储在ir.values中)

Python Odoo 10在XML中使用配置值(存储在ir.values中),python,xml,openerp,odoo-10,Python,Xml,Openerp,Odoo 10,我想在侧边栏中创建一个菜单,显示特定类别的产品。我想为这个任务使用一个默认设置的过滤器 但是,我不知道如何在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"&g

我想在侧边栏中创建一个菜单,显示特定类别的产品。我想为这个任务使用一个默认设置的过滤器

但是,我不知道如何在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"
       />

我的分类产品搜索
产品模板
我的产品类别
ir.actions.act\u窗口
产品模板
看板、树、表格
{“搜索\默认\筛选\我的分类”:1}
我希望,当使用模型“product.template”将“my_category”添加到ir.values表时,该值将以某种方式添加到上下文中-事实并非如此&我收到一个Odoo客户端错误NameError:name“my_category”未定义


有人知道我如何在XML视图中使用ir.values表的值吗?或者至少在
上下文
标记中调用python方法?或者我的任务还有其他解决方案吗?谢谢你的帮助

我在奥多v8中试过这个,它对我很有效

首先,只使用上下文创建没有域的筛选器

<filter string="My Category" name="filter_my_categ" domain="[]" context="{'custom_filter':1}"/>
就这些。
谢谢。

除了Odoo8中的解决方案(由Viki Chavada发布)之外,下面是Odoo 10的python代码的样子&扩展product.template:

class ProductTemplate(models.Model):
    _inherit = "product.template"

    @api.model
    def search(self, args, offset=0, limit=None, order=None, count=False):
        if self.env.context.get('custom_filter', False):
            category = self.env['ir.values'].get_default('my.config', 'my_category')
            args.append(['categ_id', 'child_of', category])

        result = super(ProductTemplate, self).search(args=args, offset=offset, limit=limit, order=order, count=count)

        return result

工作起来很有魅力!谢谢
class ProductTemplate(models.Model):
    _inherit = "product.template"

    @api.model
    def search(self, args, offset=0, limit=None, order=None, count=False):
        if self.env.context.get('custom_filter', False):
            category = self.env['ir.values'].get_default('my.config', 'my_category')
            args.append(['categ_id', 'child_of', category])

        result = super(ProductTemplate, self).search(args=args, offset=offset, limit=limit, order=order, count=count)

        return result