<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="action_bi_view_editor_view_form" model="ir.actions.act_window">
        <field name="name">Custom BI Views</field>
        <field name="res_model">bve.view</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to create a Custom Query Object.
            </p>
            <p>

            </p>
        </field>
    </record>
    <!--
        these menu items are parented to the legacy base.menu_board_root menu
        to avoid a dependency on the spreadsheet module through
        spreadsheet_dashboard. in case spreadsheet_dashboard is installed, the
        auto-installable bi_view_editor_spreadsheet_dashboard module moves
        them to the spreadsheet_dashboard menu.
    -->
    <menuitem
        id="menu_bi_view_editor_view"
        parent="base.menu_reporting_config"
        action="action_bi_view_editor_view_form"
        sequence="50"
    />
    <!-- Menu that will contain all the BI views generated by this module -->
    <menuitem
        id="menu_bi_view_editor_custom_reports"
        name="Custom BI Views"
        parent="base.menu_board_root"
        sequence="120"
    />
    <record id="view_bi_view_editor_view_tree" model="ir.ui.view">
        <field name="model">bve.view</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name" />
            </tree>
        </field>
    </record>
    <record id="view_bi_view_editor_view_form" model="ir.ui.view">
        <field name="model">bve.view</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button
                        name="action_reset"
                        type="object"
                        states="created"
                        string="Reset to Draft"
                        groups="bi_view_editor.group_bve_manager"
                    />
                    <button
                        name="action_create"
                        type="object"
                        states="draft"
                        string="Generate BI View"
                        class="oe_highlight"
                        groups="bi_view_editor.group_bve_manager"
                    />
                    <button
                        name="open_view"
                        type="object"
                        states="created"
                        string="Open BI View"
                        class="oe_highlight"
                        groups="bi_view_editor.group_bve_manager"
                    />
                    <button
                        name="%(base.act_menu_create)d"
                        type="action"
                        states="created"
                        groups="bi_view_editor.group_bve_manager"
                        icon="fa-align-justify"
                        string="Create a Menu"
                        target="new"
                        context="{'default_menu_id': %(bi_view_editor.menu_bi_view_editor_custom_reports)d}"
                    />
                    <field
                        name="state"
                        widget="statusbar"
                        statusbar_visible="draft,created"
                        statusbar_colors='{"draft":"blue","created":"blue"}'
                    />
                </header>
                <sheet>
                    <h1>
                        <field
                            name="name"
                            attrs="{'readonly': [('state','=','created')]}"
                            colspan="4"
                        />
                    </h1>
                    <notebook>
                        <page string="Query Builder">
                            <field
                                name="data"
                                widget="BVEEditor"
                                nolabel="1"
                                attrs="{'readonly': [('state','=','created')]}"
                            />
                        </page>
                        <page
                            string="ER Diagram"
                            attrs="{'invisible': [('er_diagram_image','=',False)]}"
                        >
                            <field nolabel="1" name="er_diagram_image" widget="image" />
                        </page>
                        <page string="Details">
                            <separator string="Fields" />
                            <field
                                name="field_ids"
                                nolabel="1"
                                attrs="{'readonly': [('state','=','created')]}"
                            >
                                <tree
                                    editable="bottom"
                                    decoration-muted="in_list == False"
                                    create="false"
                                >
                                    <field name="sequence" widget="handle" />
                                    <field name="description" string="Field" />
                                    <field name="model_id" readonly="1" />
                                    <field name="table_alias" />
                                    <field name="ttype" invisible="1" />
                                    <field
                                        name="row"
                                        attrs="{'invisible': [('ttype','in',('float', 'integer', 'monetary'))]}"
                                    />
                                    <field
                                        name="column"
                                        attrs="{'invisible': [('ttype','in',('float', 'integer', 'monetary'))]}"
                                    />
                                    <field
                                        name="measure"
                                        attrs="{'invisible': [('ttype','not in',('float', 'integer', 'monetary'))]}"
                                    />
                                    <field name="in_list" widget="boolean_toggle" />
                                    <field
                                        name="list_attr"
                                        attrs="{'invisible': ['|',('in_list','=',False),('ttype','not in',('float', 'integer'))]}"
                                    />
                                </tree>
                            </field>
                            <separator string="Relations" />
                            <field
                                name="relation_ids"
                                nolabel="1"
                                attrs="{'readonly': [('state','=','created')]}"
                            >
                                <tree editable="bottom" create="false">
                                    <field name="sequence" widget="handle" />
                                    <field name="description" string="Field" />
                                    <field name="model_id" readonly="1" />
                                    <field name="table_alias" />
                                    <field name="join_model_id" readonly="1" />
                                    <field name="join_node" />
                                    <field name="left_join" />
                                </tree>
                            </field>
                        </page>
                        <page string="SQL" groups="base.group_no_one">
                            <field name="query" />
                            <group>
                                <field name="over_condition" />
                            </group>
                        </page>
                        <page string="Security">
                            <field nolabel="1" name="group_ids" />
                        </page>
                        <page string="Notes">
                            <field name="note" nolabel="1" colspan="4" />
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>
</odoo>
