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

    <!-- Product Attributes -->

    <record id="product_attribute_tree_view" model="ir.ui.view">
        <field name="name">product.config.product.attribute.tree</field>
        <field name="model">product.attribute</field>
        <field name="inherit_id" ref="product.attribute_tree_view" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='name']" position="after">
                <field name="search_ok" />
            </xpath>
        </field>
    </record>

    <record model="ir.ui.view" id="product_attribute_form_view">
        <field name="name">product.attribute.form.view</field>
        <field name="model">product.attribute</field>
        <field name="priority">100</field>
        <field name="inherit_id" ref="product.product_attribute_view_form" />
        <field name="arch" type="xml">
            <xpath expr="//form//group[@name='main_fields']" position="before">
                <div
                    class="oe_left"
                    style="width: 500px;"
                    invisible="not context.get('flag_config_ok')"
                >
                    <field name="image" widget="image" class="oe_avatar oe_left" />
                </div>
            </xpath>
            <xpath expr="//group[@name='main_fields']" position="inside">
                <field name="active" invisible="not context.get('flag_config_ok')" />
            </xpath>
            <xpath expr="//field[@name='create_variant']" position="attributes">
                <attribute name="groups">base.group_no_one</attribute>
            </xpath>
            <xpath expr="//notebook//page" position="after">
                <page
                    string="Configurator"
                    groups="product_configurator.group_product_configurator_manager"
                    invisible="not context.get('flag_config_ok')"
                >
                    <group>
                        <group>
                            <field name="required" />
                            <field
                                name="multi"
                                attrs="{'readonly': [('val_custom','=',True)]}"
                                force_save="1"
                            />
                            <field
                                name="val_custom"
                                attrs="{'readonly': [('multi', '=', True)]}"
                                force_save="1"
                            />
                        </group>
                        <group>
                            <field name="uom_id" />
                        </group>
                        <field name="description" colspan="4" />
                    </group>
                </page>
                <page
                    string="Custom Values"
                    invisible="not context.get('flag_config_ok')"
                    attrs="{'invisible': [('val_custom', '!=', True)]}"
                    groups="product_configurator.group_product_configurator_manager"
                >
                    <group>
                        <group>
                            <field name="custom_type" />
                            <field
                                name="min_val"
                                attrs="{'invisible': [('custom_type','not in',['integer','float'])]}"
                            />
                            <field
                                name="max_val"
                                attrs="{'invisible': [('custom_type','not in',['integer','float'])]}"
                            />
                        </group>
                        <group>
                            <field name="search_ok" />
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_attributes_view">
        <field name="name">Attributes</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.attribute</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'flag_config_ok': True}</field>
    </record>

    <menuitem
        id="menu_attribute_action_configuration"
        action="action_attributes_view"
        parent="menu_product_configurable_settings"
        sequence="10"
        groups="product.group_product_variant"
    />

    <!-- Product Attribute Value -->

    <record
        id="product_template_attribute_value_view_tree_weight_extra"
        model="ir.ui.view"
    >
        <field
            name="name"
        >product.template.attribute.value.view.tree.weight.extra</field>
        <field name="model">product.template.attribute.value</field>
        <field
            name="inherit_id"
            ref="product.product_template_attribute_value_view_tree"
        />
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price_extra']" position="after">
                <field
                    name="weight_extra"
                    groups="product_configurator.group_product_configurator_manager"
                />
            </xpath>
        </field>
    </record>

    <record
        id="product_template_attribute_value_view_form_weight_extra"
        model="ir.ui.view"
    >
        <field
            name="name"
        >product.template.attribute.value.view.form.weight.extra</field>
        <field name="model">product.template.attribute.value</field>
        <field
            name="inherit_id"
            ref="product.product_template_attribute_value_view_form"
        />
        <field name="type">form</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price_extra']" position="before">
                <field
                    name="weight_extra"
                    groups="product_configurator.group_product_configurator_manager"
                />
            </xpath>
        </field>
    </record>

    <!-- Product Attribute Value -->

    <record id="variants_tree_view" model="ir.ui.view">
        <field name="name">product.attribute.value.tree</field>
        <field name="model">product.attribute.value</field>
        <field name="arch" type="xml">
            <tree>
                <field name="sequence" widget="handle" />
                <field name="attribute_id" />
                <field name="name" />
            </tree>
        </field>
    </record>

    <record model="ir.ui.view" id="product_attribute_value_form_view">
        <field name="name">product.config.product.attribute.value.form.view</field>
        <field name="model">product.attribute.value</field>
        <field name="arch" type="xml">
            <form string="Product Attribute Values">
                <sheet>
                    <field name="image" widget="image" class="oe_avatar" />
                    <div class="oe_left" style="width: 500px;">
                        <div class="oe_title" style="width: 390px;">
                            <label class="oe_edit_only" for="name" string="Value" />
                            <h1><field name="name" class="oe_inline" /></h1>
                            <label for="active" /><field name="active" />
                        </div>
                    </div>
                    <group>
                        <group>
                            <field name="attribute_id" />
                        </group>
                        <group>
                            <field name="product_id" />
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="variants_action" model="ir.actions.act_window">
        <field name="name">Attribute Values</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.attribute.value</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem
        id="menu_variants_action_configuration"
        action="variants_action"
        parent="menu_product_configurable_settings"
        sequence="20"
        groups="product.group_product_variant"
    />

    <!-- Product Attribute Line -->
    <record id="product_template_attribute_line_form_config" model="ir.ui.view">
        <field name="name">product.template.attribute.line.form</field>
        <field name="model">product.template.attribute.line</field>
        <field name="inherit_id" ref="product.product_template_attribute_line_form" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='attribute_id']" position="attributes">
                <attribute
                    name="context"
                >{'flag_config_ok': context.get('default_config_ok', False)}</attribute>
            </xpath>
        </field>
    </record>

</odoo>
