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

    <record id="sql_export_view_form" model="ir.ui.view">
        <field name="model">sql.export</field>
        <field
            name="inherit_id"
            ref="sql_request_abstract.view_sql_request_mixin_form"
        />
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <field name="query" position="after">
                <field name="use_properties" invisible="1" />
            </field>
            <button name="button_preview_sql_expression" position="attributes">
                <attribute name="states" />
                <attribute
                    name="attrs"
                >{'invisible': [('use_properties', '=', True)]}</attribute>
            </button>
            <xpath expr="//header" position="inside">
                <button
                    name="export_sql_query"
                    string="Execute Query"
                    states="sql_valid"
                    type="object"
                    class="oe_highlight"
                    icon="fa-arrow-right text-success"
                />
                <button
                    name="configure_properties"
                    states="draft"
                    string="Configure Properties"
                    type="object"
                    class="oe_highlight"
                    icon="fa-arrow-right text-success"
                />
            </xpath>
            <group name="group_main_info" position="inside">
                <group name="option">
                    <field
                        name="file_format"
                        attrs="{'readonly': [('state', '!=', 'draft')]}"
                    />
                    <field
                        name="keep_generated_file"
                        attrs="{'invisible': [('file_format', '!=', 'csv')], 'required': [('file_format', '=', 'csv')], 'readonly': [('state', '!=', 'draft')]}"
                        groups="base.group_no_one"
                    />
                    <field
                        name="copy_options"
                        attrs="{'invisible': [('file_format', '!=', 'csv')], 'required': [('file_format', '=', 'csv')], 'readonly': [('state', '!=', 'draft')]}"
                    />
                    <field
                        name="encoding"
                        attrs="{'readonly': [('state', '!=', 'draft')]}"
                    />
                </group>
            </group>
            <field name="query" position="before">
                <p
                    colspan="2"
                    attrs="{'invisible': [('use_properties', '=', False)]}"
                > In case of use of properties in the query, use this syntax : &#37;&#37;(Property String)s. <br
                    />
                                Example : SELECT id FROM sale_order WHERE create_date > &#37;&#37;(Start Date)s</p>
            </field>
        </field>
    </record>

    <record id="sql_export_view_tree" model="ir.ui.view">
        <field name="model">sql.export</field>
        <field
            name="inherit_id"
            ref="sql_request_abstract.view_sql_request_mixin_tree"
        />
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <field name="state" position="after">
                <field name="last_execution_date" optional="hide" />
                <field name="last_execution_uid" optional="hide" />
                <button
                    name="export_sql_query"
                    string="Execute Query"
                    states="sql_valid"
                    type="object"
                    icon="fa-arrow-right text-success"
                />
            </field>
        </field>
    </record>

    <record id="sql_export_tree_action" model="ir.actions.act_window">
        <field name="name">SQL Exports</field>
        <field name="res_model">sql.export</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem
        id="sql_export_menu_view"
        name="Sql Export"
        parent="spreadsheet_dashboard.spreadsheet_dashboard_menu_root"
        action="sql_export_tree_action"
        sequence="15"
    />

</odoo>
