<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

        <record id="purchase_order_lot_form" model="ir.ui.view">
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form" />
            <field name="arch" type="xml">
                <xpath
                expr="//field[@name='order_line']/tree/field[@name='name']"
                position="after"
            >
                <field name="tracking" invisible="1" />
                <field
                    name="lot_id"
                    domain="[('product_id','=', product_id)]"
                    context="{'default_product_id': product_id}"
                    groups="stock.group_production_lot"
                    attrs="{'invisible': [('tracking', '=', 'none')]}"
                />
                </xpath>
            </field>
        </record>

        <record id="purchase_order_line_lot_form" model="ir.ui.view">
            <field name="model">purchase.order.line</field>
            <field name="inherit_id" ref="purchase.purchase_order_line_form2" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='product_id']" position="after">
                    <field name="tracking" invisible="1" />
                    <field
                    name="lot_id"
                    domain="[('product_id','=', product_id)]"
                    context="{'default_product_id': product_id}"
                    groups="stock.group_production_lot"
                    attrs="{'invisible': [('tracking', '=', 'none')]}"
                />
                </xpath>
            </field>
        </record>

        <record id="view_purchase_order_filter" model="ir.ui.view">
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.view_purchase_order_filter" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='name']" position="after">
                    <field
                    name="order_line"
                    string="Serial Number"
                    filter_domain="[('order_line.lot_id.name','ilike',self)]"
                />
                </xpath>
            </field>
        </record>

</odoo>
