<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record model="ir.ui.view" id="view_move_form_supplied_product">
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']/.." position="inside">
                <field
                    name="use_only_supplied_product"
                    attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"
                    widget="boolean_toggle"
                />
            </xpath>
            <xpath
                expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']"
                position="attributes"
            >
                <attribute name="context">{
                    'restrict_supplier_id': parent.partner_id,
                    'use_only_supplied_product':
                        parent.move_type in ('in_invoice', 'in_refund', 'in_receipt')
                        and parent.use_only_supplied_product
                }</attribute>
            </xpath>
        </field>
    </record>
    <record model="ir.ui.view" id="view_move_line_form_supplied_product">
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_form" />
        <field name="arch" type="xml">
            <field name="product_id" position="attributes">
                <attribute name="context">{
                    'restrict_supplier_id': parent.partner_id,
                    'use_only_supplied_product':
                        parent.move_type in ('in_invoice', 'in_refund', 'in_receipt')
                        and parent.use_only_supplied_product
                }</attribute>
            </field>
        </field>
    </record>
</odoo>
