<?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" readonly="state != 'draft'"/>
                    <label for="purchase_vendor_bill_id" string="Auto-Complete" class="oe_edit_only" invisible="state != 'draft' or move_type != 'in_invoice'"/>
                    <field name="purchase_vendor_bill_id" nolabel="1" invisible="state != 'draft' or move_type != 'in_invoice'" readonly="state != 'draft'" class="oe_edit_only" domain="partner_id and [('partner_id.commercial_partner_id', '=', commercial_partner_id)] or []" 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']/list/field[@name='company_id']" position="after">
                <field name="purchase_line_id" groups="purchase.group_purchase_user" column_invisible="True"/>
                <field name="purchase_order_id" groups="purchase.group_purchase_user" column_invisible="parent.move_type != 'in_invoice'" optional="hide"/>
            </xpath>
            <xpath expr="//field[@name='line_ids']/list/field[@name='company_id']" position="after">
                <field name="purchase_line_id" groups="purchase.group_purchase_user" column_invisible="True"/>
            </xpath>
            <xpath expr="//div[@name='button_box']" position="inside">
                <button class="oe_stat_button" name="action_purchase_matching" type="object" groups="purchase.group_purchase_user" icon="fa-bullseye" invisible="not partner_id or move_type not in ('in_invoice', 'in_refund') or is_purchase_matched">
                    <div class="o_field_statinfo">
                        <span class="o_stat_text">Purchase Matching</span>
                    </div>
                </button>
                <button class="oe_stat_button" name="action_view_source_purchase_orders" type="object" groups="purchase.group_purchase_user" icon="fa-pencil-square-o" invisible="purchase_order_count == 0 or move_type not in ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt')">
                    <field string="Purchases" name="purchase_order_name" widget="statinfo" invisible="purchase_order_count != 1"/>
                    <field string="Purchases" name="purchase_order_count" widget="statinfo" invisible="purchase_order_count == 1"/>
                </button>
            </xpath>
        </data>