<?xml version="1.0"?>
<data><!-- Auto-complete could be done from either a bill either a purchase order -->
            <field name="invoice_vendor_bill_id" position="after">
                <t groups="purchase.group_purchase_user">
                    <field name="purchase_id" invisible="1"/>
                    <label for="purchase_vendor_bill_id" string="Auto-Complete" class="oe_edit_only" attrs="{'invisible': ['|', ('state','!=','draft'), ('move_type', '!=', 'in_invoice')]}"/>
                    <field name="purchase_vendor_bill_id" nolabel="1" attrs="{'invisible': ['|', ('state','!=','draft'), ('move_type', '!=', 'in_invoice')]}" class="oe_edit_only" domain="partner_id and [('company_id', '=', company_id), ('partner_id.commercial_partner_id', '=', commercial_partner_id)] or [('company_id', '=', company_id)]" placeholder="Select a purchase order or an old bill" context="{'show_total_amount': True}" options="{'no_create': True, 'no_open': True}"/>
                </t>
            </field>
            <label name="invoice_vendor_bill_id_label" position="attributes">
                <attribute name="groups">!purchase.group_purchase_user</attribute>
            </label>
            <field name="invoice_vendor_bill_id" position="attributes">
                <attribute name="groups">!purchase.group_purchase_user</attribute>
            </field>
            <!-- Add link to purchase_line_id to account.move.line -->
            <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='company_id']" position="after">
                <field name="purchase_line_id" groups="purchase.group_purchase_user" invisible="1"/>
                <field name="purchase_order_id" groups="purchase.group_purchase_user" attrs="{'column_invisible': [('parent.move_type', '!=', 'in_invoice')]}" optional="hide"/>
            </xpath>
            <xpath expr="//field[@name='line_ids']/tree/field[@name='company_id']" position="after">
                <field name="purchase_line_id" groups="purchase.group_purchase_user" invisible="1"/>
            </xpath>
            <xpath expr="//div[@name='button_box']" position="inside">
                <button class="oe_stat_button" name="action_view_source_purchase_orders" type="object" groups="purchase.group_purchase_user" icon="fa-pencil-square-o" attrs="{'invisible': ['|', ('purchase_order_count', '=', 0), ('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}">
                    <field string="Purchases" name="purchase_order_count" widget="statinfo"/>
                </button>
            </xpath>
        </data>