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

    <!-- Wizard Form View -->
    <record id="view_hazard_inventory_history_wizard" model="ir.ui.view">
        <field name="name">hazard.inventory.history.wizard.form</field>
        <field name="model">hazard.inventory.history.wizard</field>
        <field name="arch" type="xml">
            <form string="Reporte Histórico de Inventario">
                <group>
                    <field name="date"/>
                </group>
                <footer>
                    <button name="action_generate_report" string="Generar Reporte" type="object" class="btn-primary"/>
                    <button string="Cancelar" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <!-- Action for the Wizard -->
    <record id="action_hazard_inventory_history_wizard" model="ir.actions.act_window">
        <field name="name">Inventario Histórico (A una fecha)</field>
        <field name="res_model">hazard.inventory.history.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

    <!-- Menu Item (Under Inventory -> Reporting) -->
    <menuitem id="menu_hazard_inventory_history"
              name="Inventario Histórico"
              parent="stock.menu_warehouse_report"
              action="action_hazard_inventory_history_wizard"
              sequence="155"/>

    <!-- Search View for the Data Model -->
    <record id="hazard_inventory_history_data_view_search" model="ir.ui.view">
        <field name="name">hazard.inventory.history.data.search</field>
        <field name="model">hazard.inventory.history.data</field>
        <field name="arch" type="xml">
            <search string="Búsqueda de Inventario Histórico">
                <field name="location_id"/>
                <field name="product_id"/>
                <field name="categ_id"/>
                <group expand="0" string="Agrupar por">
                    <filter string="Ubicación (Sucursal)" name="group_by_location" context="{'group_by':'location_id'}"/>
                    <filter string="Producto" name="group_by_product" context="{'group_by':'product_id'}"/>
                    <filter string="Categoría" name="group_by_categ" context="{'group_by':'categ_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Tree View for the Data Model -->
    <record id="hazard_inventory_history_data_view_tree" model="ir.ui.view">
        <field name="name">hazard.inventory.history.data.tree</field>
        <field name="model">hazard.inventory.history.data</field>
        <field name="arch" type="xml">
            <tree string="Reporte Histórico de Inventario" create="false" edit="false" delete="false">
                <field name="location_id"/>
                <field name="product_id"/>
                <field name="categ_id" optional="hide"/>
                <field name="quantity" sum="Total Cantidad"/>
                <field name="standard_price" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                <field name="list_price" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                <field name="total_cost" sum="Costo Total" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                <field name="total_sale" sum="Venta Total" widget="monetary" options="{'currency_field': 'currency_id'}"/>
            </tree>
        </field>
    </record>

    <!-- Pivot View for the Data Model -->
    <record id="hazard_inventory_history_data_view_pivot" model="ir.ui.view">
        <field name="name">hazard.inventory.history.data.pivot</field>
        <field name="model">hazard.inventory.history.data</field>
        <field name="arch" type="xml">
            <pivot string="Reporte Histórico Dinámico" sample="1" disable_linking="True">
                <field name="location_id" type="row"/>
                <field name="product_id" type="row"/>
                <field name="quantity" type="measure"/>
                <field name="total_cost" type="measure"/>
                <field name="total_sale" type="measure"/>
            </pivot>
        </field>
    </record>

</odoo>
