<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!--  Dynamic fields view tree -->
    <record id="dynamic_fields_view_list" model="ir.ui.view">
        <field name="name">dynamic.fields.view.list</field>
        <field name="model">dynamic.fields</field>
        <field name="arch" type="xml">
            <list>
                <field name="name"/>
                <field name="field_description"/>
                <field name="model_id"/>
                <field name="status"/>
            </list>
        </field>
    </record>
    <!--  Dynamic fields view form -->
    <record id='dynamic_fields_view_form' model='ir.ui.view'>
        <field name="name">dynamic.fields.view.form</field>
        <field name="model">dynamic.fields</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_create_dynamic_field"
                            string="Create Field" type="object"
                            class="oe_highlight"
                            invisible="status in ('form','list')"
                            groups="all_in_one_dynamic_custom_fields.group_all_in_one_dynamic_custom_fields_administrator"/>
                    <field name="status" widget="statusbar"
                           statusbar_visible="draft,form"/>
                </header>
                <sheet>
                    <group>
                        <group string="Field Info">
                            <field name="name" readonly="status != 'draft'"/>
                            <field name="field_description"
                                   readonly="status != 'draft'"/>
                            <field name="state" readonly="1"
                                   groups="base.group_no_one"/>
                            <field name="model_id"
                                   options='{"no_open": True, "no_create": True}'
                                   readonly="status != 'draft'"/>
                            <field name="field_type"
                                   readonly="status != 'draft'"/>
                            <field name="selection_field"
                                   placeholder="Eg: [('blue', 'Blue'),('yellow', 'Yellow')]"
                                   required="field_type in ('selection','reference')"
                                   readonly="field_type not in ('selection','reference') and status != 'draft'"
                                   invisible="field_type not in ('selection','reference')"/>
                            <field name="ref_model_id"
                                   options='{"no_open": True, "no_create": True}'
                                   required="field_type in ('many2one','many2many')"
                                   readonly="field_type not in ('many2one','many2many') or status != 'draft'"
                                   invisible="field_type not in ('many2one','many2many')"/>
                            <field name="widget_id" widget="selection"
                                   invisible="field_type not in ('binary','many2many', 'selection', 'float', 'many2one')"
                                   readonly="status != 'draft'"/>
                            <field name="required"
                                   readonly="status != 'draft'"/>
                            <field name="model" invisible="1"/>
                            <field name="form_view_ids" invisible="1"/>
                            <field name="tree_view_ids" invisible="1"/>
                            <field name="form_view_id"
                                   options='{"no_open": True, "no_create": True}'
                                   readonly="status != 'draft'"/>
                            <field name="form_view_inherit_id"/>
                        </group>
                        <group string="Tree View">
                            <field name="add_field_in_tree"
                                   readonly="status != 'draft'"/>
                            <field name="tree_view_id"
                                   options='{"no_open": True, "no_create": True}'
                                   invisible="not add_field_in_tree"
                                   required="add_field_in_tree == 'True'"
                                   readonly="status != 'draft'"/>
                            <field name="tree_view_inherit_id"
                                   invisible="not add_field_in_tree"/>
                            <field name="tree_field_ids" invisible="1"/>
                            <field name="tree_field_id" required="add_field_in_tree" invisible="not add_field_in_tree"/>
                            <field name="tree_field_position" required="add_field_in_tree" invisible="not add_field_in_tree"/>
                            <field name="is_visible_in_tree_view" required="add_field_in_tree" invisible="not add_field_in_tree"/>
                        </group>
                        <group string="Position">
                            <field name="position_field_id"
                                   options='{"no_open": True, "no_create": True}'
                                   readonly="status != 'draft'"/>
                            <field name="position"
                                   readonly="status != 'draft'"/>
                        </group>
                    </group>
                    <group string="Extra Properties">
                        <group>
                            <field name="extra_features"
                                   readonly="status != 'draft'"/>
                        </group>
                        <group invisible="not extra_features">
                            <field name="help" readonly="status != 'draft'"/>
                        </group>
                        <group invisible="not extra_features">
                            <field name="readonly"
                                   readonly="status != 'draft'"/>
                            <field name="store" readonly="status != 'draft'"/>
                            <field name="index" readonly="status != 'draft'"/>
                            <field name="copied" readonly="status != 'draft'"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!--    Dynamic fields action-->
    <record id='dynamic_fields_action' model='ir.actions.act_window'>
        <field name="name">Custom Dynamic Fields</field>
        <field name="res_model">dynamic.fields</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create New Custom Dynamic Field!
            </p>
        </field>
    </record>
    <!--    All in One Custom Dynamic Fields root menu-->
    <menuitem id="menu_all_in_one_dynamic_custom_fields_root"
              name="All in One Custom Dynamic Fields"
              groups="group_all_in_one_dynamic_custom_fields_user,group_all_in_one_dynamic_custom_fields_administrator"
              web_icon="all_in_one_dynamic_custom_fields,static/description/icon.png"
              sequence="01"/>
    <!--    Create custom dynamic fields menu-->
    <menuitem id="menu_create_custom_dynamic_fields" name="Fields"
              parent="menu_all_in_one_dynamic_custom_fields_root" sequence="1"/>

    <menuitem id="menu_create_fields" name="Create Fields"
              parent="menu_all_in_one_dynamic_custom_fields_root"
              action="dynamic_fields_action"
              groups="group_all_in_one_dynamic_custom_fields_user,group_all_in_one_dynamic_custom_fields_administrator"
              sequence="2"/>
</odoo>
