<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <!-- Search RFQ -->
    <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="inherit_id" ref="purchase.view_purchase_order_filter" />
        <field name="arch" type="xml">
            <xpath expr="//search/separator[1]" position="after">
                <filter
                    name="wa_accepted"
                    string="WA Accepted"
                    domain="[('wa_accepted', '=', True)]"
                />
                <filter
                    name="wa_not_accepted"
                    string="WA Not Accepted"
                    domain="[('wa_accepted', '=', False)]"
                />
                <separator />
            </xpath>
        </field>
    </record>
    <!-- Search Purchase Order -->
    <record id="purchase_order_view_search" model="ir.ui.view">
        <field name="name">purchase.order.select</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_view_search" />
        <field name="arch" type="xml">
            <xpath expr="//search/separator[1]" position="after">
                <filter
                    name="wa_accepted"
                    string="WA Accepted"
                    domain="[('wa_accepted', '=', True)]"
                />
                <filter
                    name="wa_not_accepted"
                    string="WA Not Accepted"
                    domain="[('wa_accepted', '=', False)]"
                />
                <separator />
            </xpath>
        </field>
    </record>
    <record id="purchase_order_form_inherit" model="ir.ui.view">
        <field name="name">purchase.order.form.inherit</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form" />
        <field name="arch" type="xml">
            <xpath expr="//button[@name='button_approve']" position="after">
                <button
                    name="action_view_wa"
                    string="Create WA"
                    type="object"
                    class="oe_highlight"
                    context="{'create_wa':True}"
                    groups="purchase_work_acceptance.group_enable_wa_on_po"
                    attrs="{'invisible': ['|', ('state', 'not in', ('purchase', 'done')), ('wa_accepted', '=', True)]}"
                />
            </xpath>
            <xpath expr="//div[hasclass('oe_button_box')]" position="inside">
                <button
                    type="object"
                    name="action_view_wa"
                    class="oe_stat_button"
                    icon="fa-clipboard"
                    attrs="{'invisible':[('wa_ids','=',[])]}"
                    groups="purchase.group_purchase_user"
                >
                    <field name="wa_count" widget="statinfo" string="WA" />
                    <field name="wa_ids" invisible="1" />
                </button>
            </xpath>
            <xpath expr="//field[@name='order_line']/tree" position="inside">
                <field name="wa_line_ids" invisible="1" />
            </xpath>
            <xpath
                expr="//field[@name='order_line']/tree//field[@name='qty_received']"
                position="attributes"
            >
                <attribute name="attrs">
                    {'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))],
                    'readonly': ['|', ('product_type', 'in', ('consu',
                    'product')), ('wa_line_ids', '!=', ())]}
                </attribute>
            </xpath>
            <xpath
                expr="//field[@name='order_line']/tree//field[@name='product_qty']"
                position="after"
            >
                <field name="qty_to_accept" string="To Accept" invisible="1" />
                <field
                    name="qty_accepted"
                    string="Accepted"
                    attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"
                />
            </xpath>
            <field name="fiscal_position_id" position="after">
                <field
                    name="wa_accepted"
                    groups="purchase_work_acceptance.group_enable_wa_on_po"
                    attrs="{'invisible': [('state', 'not in', ('purchase', 'done'))]}"
                />
            </field>
        </field>
    </record>
</odoo>
