<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 Tecnativa - Sergio Teruel
     Copyright 2019 Tecnativa - Pedro M. Baeza
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="name">Sale Elaboration</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='order_line']/form/group" position="inside">
                <group string="Elaborations" name="elaboration">
                    <field name="elaboration_profile_id" invisible="1" />
                    <field
                        name="elaboration_ids"
                        widget="many2many_tags"
                        readonly="not product_updatable or parent.state in ('done', 'cancel')"
                        domain="elaboration_profile_id and [('profile_ids', 'in', [elaboration_profile_id])] or []"
                    />
                    <field
                        name="elaboration_note"
                        readonly="not product_updatable or parent.state in ('done', 'cancel')"
                    />
                    <field
                        name="elaboration_price_unit"
                        readonly="1"
                        widget="monetary"
                        invisible="not elaboration_ids"
                    />
                </group>
            </xpath>
            <xpath
                expr="//field[@name='order_line']/list//field[@name='price_unit']"
                position="after"
            >
                <field name="elaboration_profile_id" column_invisible="1" />
                <field
                    name="elaboration_ids"
                    widget="many2many_tags"
                    readonly="not product_updatable or parent.state in ('done', 'cancel')"
                    domain="elaboration_profile_id and [('profile_ids', 'in', [elaboration_profile_id])] or []"
                    optional="show"
                />
                <field
                    name="elaboration_note"
                    readonly="not product_updatable or parent.state in ('done', 'cancel')"
                    optional="show"
                />
                <field
                    name="elaboration_price_unit"
                    readonly="1"
                    widget="monetary"
                    optional="hide"
                />
            </xpath>
            <xpath
                expr="//field[@name='order_line']/kanban//field[@name='currency_id']"
                position="after"
            >
                <field name="elaboration_ids" />
                <field name="elaboration_note" />
                <field name="elaboration_price_unit" />
            </xpath>
            <xpath
                expr="//field[@name='order_line']/kanban//field[@name='price_unit']/.."
                position="after"
            >
                <t t-if="record.elaboration_ids.raw_value.length gt 0">
                    <div>
                            Elaboration price: <field
                        name="elaboration_price_unit"
                        widget="monetary"
                    />
                    </div>
                </t>
            </xpath>
            <xpath
                expr="//field[@name='order_line']/kanban//field[@name='discount']/../.."
                position="after"
            >
                <t t-if="record.elaboration_ids.raw_value.length gt 0">
                    <div class="row mt8">
                        <div class="col-12">
                            <strong>
                                <field name="elaboration_ids" widget="many2many_tags" />
                            </strong>
                        </div>
                    </div>
                </t>
            </xpath>
        </field>
    </record>
</odoo>
