如何在 Odoo 12 的 pos.order 模型中添加产品过滤器

How to add Product Filter in pos.order model in Odoo 12

我想添加一个过滤器名称“product”作为产品模型中的默认过滤器。 我已经给出了我想要的过滤器的图片[添加自定义过滤器中的过滤器]。任何帮助将不胜感激。

根据评论,您可以在 odoo>addons>purchase>views>purchase_views.xml[=16 中访问该视图的源代码=]

   <record id="view_purchase_order_filter" model="ir.ui.view">
        <field name="name">request.quotation.select</field>
        <field name="model">purchase.order</field>
        <field name="arch" type="xml">
            <search string="Search Purchase Order">
                <field name="name" string="Order"
                    filter_domain="['|', '|', ('name', 'ilike', self), ('partner_ref', 'ilike', self), ('partner_id', 'child_of', self)]"/>
                <field name="partner_id" operator="child_of"/>
                <field name="user_id"/>
                <field name="product_id"/>
                <filter name="my_purchases" string="My Purchases" domain="[('user_id', '=', uid)]"/>
                <filter string="Starred" name="starred" domain="[('priority', '=', '1')]"/>
                <separator/>
                <filter name="draft" string="RFQs" domain="[('state', 'in', ('draft', 'sent', 'to approve'))]"/>
                <separator/>
                <filter name="approved" string="Purchase Orders" domain="[('state', 'in', ('purchase', 'done'))]"/>
                <filter name="to_approve" string="To Approve" domain="[('state', '=', 'to approve')]"/>
                <separator/>
                <filter name="order_date" string="Order Date" date="date_order"/>
                <filter name="draft_rfqs" string="Draft RFQs" domain="[('state', '=', 'draft')]"/>
                <filter name="waiting_rfqs" string="Waiting RFQs" domain="[('state', '=', 'sent'), ('date_order', '&gt;=', datetime.datetime.now())]"/>
                <filter name="late_rfqs" string="Late RFQs" domain="[('state', 'in', ['draft', 'sent', 'to approve']),('date_order', '&lt;', datetime.datetime.now())]"/>
                <separator/>
                <filter invisible="1" string="Late Activities" name="activities_overdue"
                    domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    help="Show all records which has next action date is before today"/>
                <filter invisible="1" string="Today Activities" name="activities_today"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"/>
                <filter invisible="1" string="Future Activities" name="activities_upcoming_all"
                    domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]"/>
                <separator/>
                <filter string="Warnings" name="activities_exception"
                    domain="[('activity_exception_decoration', '!=', False)]"/>
                <group expand="0" string="Group By">
                    <filter string="Vendor" name="vendor" domain="[]" context="{'group_by': 'partner_id'}"/>
                    <filter string="Purchase Representative" name="representative" domain="[]" context="{'group_by': 'user_id'}"/>
                    <filter string="Order Date" name="order_date" domain="[]" context="{'group_by': 'date_order'}"/>
                </group>
            </search>
        </field>
    </record>

要添加新的自定义过滤器,您应该像下面这样继承操作的搜索视图:

    <record id="pos_order_view_search_inherit_product_filter" model="ir.ui.view">
        <field name="name">pos.order.search.inherit.product.filter</field>
        <field name="model">pos.order</field>
        <field name="mode">primary</field>
        <field name="inherit_id" ref="view_pos_order_search"/>
        <field name="arch" type="xml">
            <xpath expr="//search" position="inside">
                <field name="lines" string="Product" filter_domain="[('lines.product_id', 'ilike', self)]"/>
            </xpath>
        </field>
    </record>

这将在搜索栏中添加按产品名称搜索的选项。

您可以创建一个自定义插件来执行此操作,或者只从后端创建一个视图(Settings/Technical/Views 菜单)。