<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 Tecnativa - Sergio Teruel
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="purchase_order_form" model="ir.ui.view">
        <field name="name">Purchase Order Secondary Unit</field>
        <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']/form//field[@name='product_qty']"
                position="before"
            >
                <t groups="uom.group_uom">
                    <field
                        name="secondary_uom_qty"
                        class="oe_inline oe_no_button"
                        attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"
                    />
                    <field
                        name="secondary_uom_id"
                        class="oe_inline"
                        domain="product_id and ['|', ('product_id', '=', product_id),
                                    '&amp;', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
                                            ('product_id', '=', False)] or [(0, '=', 1)]"
                        options="{'no_create': True}"
                        attrs="{'readonly': [('state', 'in', ('purchase', 'done', 'cancel'))], 'required': [('secondary_uom_qty', '!=', 0.0)]}"
                    />
                </t>
            </xpath>
            <xpath
                expr="//field[@name='order_line']/tree//field[@name='product_qty']"
                position="before"
            >
                <field
                    name="secondary_uom_qty"
                    attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"
                    groups="uom.group_uom"
                    optional="show"
                />
                <field
                    name="secondary_uom_id"
                    domain="product_id and ['|', ('product_id', '=', product_id),
                                '&amp;', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
                                         ('product_id', '=', False)] or [(0, '=', 1)]"
                    options="{'no_create': True}"
                    attrs="{'readonly': [('state', 'in', ('purchase','done', 'cancel'))], 'required': [('secondary_uom_qty', '!=', 0.0)]}"
                    groups="uom.group_uom"
                    optional="show"
                />
            </xpath>
        </field>
    </record>
</odoo>
