<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_repair_order_tree" model="ir.ui.view">
        <field name="name">repair.order.tree</field>
        <field name="model">repair.order</field>
        <field name="inherit_id" ref="repair.view_repair_order_tree" />
        <field name="arch" type="xml">
            <field name="product_id" position="after">
                <field name="refurbish_product_id" />
            </field>
        </field>
    </record>
    <record id="view_repair_order_form" model="ir.ui.view">
        <field name="name">repair.order.form</field>
        <field name="model">repair.order</field>
        <field name="inherit_id" ref="repair.view_repair_order_form" />
        <field name="arch" type="xml">
            <field name="location_id" position="after">
                <field
                    name="location_dest_id"
                    attrs="{'invisible': [('to_refurbish', '=', False)], 'required': [('to_refurbish', '=', True)]}"
                />
            </field>
            <xpath expr="//group[1]" position="inside">
                <group>
                    <field name="to_refurbish" />
                </group>
                <group attrs="{'invisible': [('to_refurbish', '=', False)]}">
                    <field
                        name="refurbish_product_id"
                        attrs="{'required': [('to_refurbish', '=', True)]}"
                    />
                    <field
                        name="refurbish_lot_id"
                        domain="[('product_id', '=', refurbish_product_id)]"
                        context="{'default_product_id': refurbish_product_id}"
                        groups="stock.group_production_lot"
                    />
                    <field
                        name="refurbish_location_dest_id"
                        attrs="{'required': [('to_refurbish', '=', True)]}"
                    />
                </group>
            </xpath>
            <field name="operations" position='attributes'>
                <attribute
                    name='context'
                >{'default_product_uom_qty': product_qty, 'to_refurbish': to_refurbish, 'refurbish_location_dest_id': location_dest_id}</attribute>
            </field>
        </field>
    </record>
    <record id="view_repair_order_form_filter" model="ir.ui.view">
        <field name="name">repair.order.select</field>
        <field name="model">repair.order</field>
        <field name="inherit_id" ref="repair.view_repair_order_form_filter" />
        <field name="arch" type="xml">
            <field name="product_id" position="after">
                <field name="to_refurbish" />
                <field name="refurbish_product_id" />
            </field>
        </field>
    </record>
</odoo>
