<?xml version="1.0" ?>
<odoo>
    <record id="stock_demand_estimate_view_tree" model="ir.ui.view">
        <field name="name">stock.demand.estimate.tree</field>
        <field name="model">stock.demand.estimate</field>
        <field name="arch" type="xml">
            <tree decoration-muted="active == False">
                <field name="date_from" string="Date From" />
                <field name="date_to" string="Date To" />
                <field name="product_id" />
                <field name="location_id" />
                <field name="product_uom_qty" />
                <field name="product_uom" />
                <field name="product_qty" />
                <field name="daily_qty" />
                <field name="active" invisible="1" />
            </tree>
        </field>
    </record>
    <record id="stock_demand_estimate_view_form" model="ir.ui.view">
        <field name="name">stock.demand.estimate.form</field>
        <field name="model">stock.demand.estimate</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        attrs="{'invisible': [('active', '=', True)]}"
                    />
                    <group>
                        <group name="dates_read" class="oe_read_only">
                            <field name="date_from" string="Date From" />
                            <field name="date_to" string="Date To" />
                            <field name="duration" string="Duration" />
                        </group>
                        <group name="dates_edit" class="oe_edit_only">
                            <field name="manual_date_from" string="Date From" />
                            <field name="manual_date_to" string="Date To" />
                            <field name="manual_duration" string="Duration" />
                        </group>
                        <group>
                            <field name="product_id" />
                            <field name="location_id" />
                            <field name="product_uom_qty" />
                            <field name="product_uom" />
                            <field name="daily_qty" />
                            <field name="active" invisible="1" />
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>
    <record id="stock_demand_estimate_view_pivot" model="ir.ui.view">
        <field name="name">stock.demand.estimate.pivot</field>
        <field name="model">stock.demand.estimate</field>
        <field name="arch" type="xml">
            <pivot string="Stock Demand Estimate">
                <field name="product_qty" type="measure" />
                <field name="product_id" type="row" />
                <field name="date_from" type="col" />
            </pivot>
        </field>
    </record>

    <record id="stock_demand_estimate_view_graph" model="ir.ui.view">
        <field name="name">stock.demand.estimate.graph</field>
        <field name="model">stock.demand.estimate</field>
        <field name="arch" type="xml">
            <graph type="bar" stacked="True">
                <field name="product_qty" type="measure" />
                <field name="date_from" />
                <field name="product_id" />
            </graph>
        </field>
    </record>

    <record id="stock_demand_estimate_view_search" model="ir.ui.view">
        <field name="name">stock.demand.estimate.search</field>
        <field name="model">stock.demand.estimate</field>
        <field name="arch" type="xml">
            <search string="Search Stock Demand Estimates">
                <field name="product_id" />
                <field name="location_id" />
                <filter
                    string="All (Active/Inactive)"
                    name="all"
                    domain="['|', ('active', '=', False), ('active', '=', True)]"
                />
                <separator />
                <filter
                    name="expired"
                    string="Expired"
                    domain="[('date_to', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                />
                <filter
                    name="not_expired"
                    string="Not Expired"
                    domain="['|', ('date_to', '=', False), ('date_to', '&gt;', context_today().strftime('%Y-%m-%d'))]"
                />
                <separator />
                <group expand="0" string="Group By">
                    <filter
                        string="Product"
                        name="groupby_product"
                        domain="[]"
                        context="{'group_by':'product_id'}"
                    />
                    <filter
                        string="Location"
                        name="groupby_location"
                        domain="[]"
                        context="{'group_by':'location_id'}"
                    />
                    <filter
                        string="Date (From)"
                        name="groupby_date_from"
                        domain="[]"
                        context="{'group_by':'date_from'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="stock_demand_estimate_action" model="ir.actions.act_window">
        <field name="name">Stock Demand Estimates</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">stock.demand.estimate</field>
        <field name="view_mode">tree,form,pivot,graph</field>
        <field name="search_view_id" ref="stock_demand_estimate_view_search" />
        <field name="context">{"search_default_not_expired": 1}</field>
    </record>
    <menuitem
        id="stock_demand_planning_menu"
        name="Demand Planning"
        parent="stock.menu_stock_root"
        sequence="10"
    />
    <menuitem
        id="stock_demand_estimate_menu"
        parent="stock_demand_planning_menu"
        action="stock_demand_estimate_action"
    />
</odoo>
