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

        <record id="budget_report_view_tree" model="ir.ui.view">
            <field name="name">budget.report.view.list</field>
            <field name="model">budget.report</field>
            <field name="arch" type="xml">
                <list string="Budget Report" create="0" action="action_open_reference" type="object">
                    <field name="date"/>
                    <field name="description"/>
                    <field name="account_id"/>
                    <field name="company_id" optional="hide"/>
                    <field name="user_id" optional="hide"/>
                    <field name="line_type" optional="hide"/>
                    <field name="budget" sum="Total Budget"/>
                    <field name="committed" sum="Total Committed"/>
                    <field name="achieved" sum="Total Achieved"/>
                </list>
            </field>
        </record>

        <record id="budget_report_view_search" model="ir.ui.view">
            <field name="name">budget.report.view.search</field>
            <field name="model">budget.report</field>
            <field name="arch" type="xml">
                <search string="Budget Report">
                    <field name="budget_analytic_id"/>
                    <field name="description"/>
                    <field name="user_id"/>
                    <field name="account_id"/>
                    <field name="company_id"/>
                    <field name="date"/>
                    <filter string="Budget" name="budget" domain="[('line_type','=','budget')]"/>
                    <filter string="Achieved" name="achieved" domain="[('line_type','=','achieved')]"/>
                    <filter string="Committed" name="committed" domain="[('line_type','=','committed')]"/>
                    <separator/>
                    <filter string="In a Budget" name="in_a_budget" domain="[('budget_analytic_id', '=', False)]"/>
                    <filter string="Open Budget" name="open_budget" domain="[('budget_analytic_id.state', '=', 'confirmed')]"/>
                    <separator/>
                    <group expand="0" string="Group By">
                        <filter string="Date" name="date" context="{'group_by':'date'}"/>
                        <filter string="Type" name="line_type" context="{'group_by':'line_type'}"/>
                        <filter string="Budget" name="budget_analytic_id" context="{'group_by':'budget_analytic_id'}"/>
                        <separator/>
                        <filter string="Account" name="account_id" context="{'group_by':'account_id'}"/>
                        <separator/>
                        <filter string="User" name="user_id" context="{'group_by':'user_id'}"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="budget_report_view_graph" model="ir.ui.view">
            <field name="name">budget.report.view.graph</field>
            <field name="model">budget.report</field>
            <field name="arch" type="xml">
                <graph string="Budget Report" type="line">
                    <field name="date" type="row"/>
                    <field name="account_id" type="col"/>
                    <field name="committed" type="measure"/>
                </graph>
            </field>
        </record>

        <record id="budget_report_view_pivot" model="ir.ui.view">
            <field name="name">budget.report.view.pivot</field>
            <field name="model">budget.report</field>
            <field name="arch" type="xml">
                <pivot string="Budget Report">
                    <field name="budget_analytic_id" type="col"/>
                    <field name="account_id"/>  <!-- do not copy the `type` with _patch_view -->
                    <field name="account_id" type="row"/>
                    <field name="budget" type="measure"/>
                    <field name="committed" type="measure"/>
                    <field name="achieved" type="measure"/>
                </pivot>
            </field>
        </record>

        <record id="budget_report_action" model="ir.actions.act_window">
            <field name="name">Budget Report</field>
            <field name="res_model">budget.report</field>
            <field name="view_mode">pivot,list,graph</field>
            <field name="context">{"search_default_open_budget":1}</field>
        </record>

        <menuitem id="budget_report_menu" name="Budget Report"
                  groups="account.group_account_readonly"
                  parent="account.account_reports_management_menu" action="budget_report_action"/>
    </data>
</odoo>
