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

        <record id="view_warehouse" model="ir.ui.view">
            <field name="name">stock.warehouse</field>
            <field name="model">stock.warehouse</field>
            <field name="arch" type="xml">
                <form string="Warehouse" create="false">
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button name="action_view_all_routes"
                                    string="Routes"
                                    icon="fa-refresh"
                                    class="oe_stat_button"
                                    type="object"/>
                            <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
                                <field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
                            </button>
                        </div>
                        <label for="name" class="oe_edit_only"/>
                        <h1><field name="name"/></h1>
                        <group>
                            <group>
                                <field name="code"/>
                            </group>
                            <group>
                                <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
                                <field name="partner_id"/>
                            </group>
                        </group>
                        <notebook colspan="4" groups="stock.group_adv_location">
                            <page string="Warehouse Configuration" colspan="4">
                                <group colspan="4">
                                    <group string="Shipments">
                                        <field name="reception_steps" widget='radio'/>
                                        <field name="delivery_steps" widget='radio'/>
                                    </group>
                                    <field name="show_resupply" invisible="1"/>
                                    <group name="group_resupply" string="Resupply" attrs="{'invisible': [('show_resupply', '!=', True)]}">
                                        <field name="warehouse_count" invisible="1"/>
                                        <field name="resupply_wh_ids" attrs="{'invisible': [('show_resupply', '!=', True)]}" domain="[('id', '!=', id)]" widget='many2many_checkboxes'/>
                                    </group>
                                </group>
                            </page>
                            <page string="Technical Information" groups='base.group_no_one'>
                                <group>
                                    <group string="Locations">
                                        <field name="wh_input_stock_loc_id" readonly="1"/>
                                        <field name="wh_qc_stock_loc_id" readonly="1"/>
                                        <field name="wh_pack_stock_loc_id" readonly="1"/>
                                        <field name="wh_output_stock_loc_id" readonly="1"/>
                                    </group>
                                    <group string="Operation Types">
                                        <field name="in_type_id" readonly="1"/>
                                        <field name="int_type_id" readonly="1"/>
                                        <field name="pick_type_id" readonly="1"/>
                                        <field name="pack_type_id" readonly="1"/>
                                        <field name="out_type_id" readonly="1"/>
                                    </group>
                                </group>
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>
        <record id="stock_warehouse_view_form_editable" model="ir.ui.view">
            <field name="name">stock.warehouse.form.editable</field>
            <field name="model">stock.warehouse</field>
            <field name="inherit_id" ref="stock.view_warehouse"/>
            <field name="groups_id" eval="[(4, ref('stock.group_stock_multi_warehouses'))]"/>
            <field name="arch" type="xml">
                <xpath expr="//form" position="attributes">
                    <attribute name="create">true</attribute>
                </xpath>
            </field>
        </record>
        <record id="view_warehouse_tree" model="ir.ui.view">
            <field name="name">stock.warehouse.tree</field>
            <field name="model">stock.warehouse</field>
            <field name="arch" type="xml">
                <tree string="Warehouse" create="false">
                    <field name="name"/>
                    <field name="active" invisible="1"/>
                    <field name="lot_stock_id" groups="stock.group_stock_multi_locations"/>
                    <field name="partner_id"/>
                </tree>
            </field>
        </record>
        <record id="stock_warehouse_view_tree_editable" model="ir.ui.view">
            <field name="name">stock.warehouse.tree.editable</field>
            <field name="model">stock.warehouse</field>
            <field name="inherit_id" ref="stock.view_warehouse_tree"/>
            <field name="groups_id" eval="[(4, ref('stock.group_stock_multi_warehouses'))]"/>
            <field name="arch" type="xml">
                <xpath expr="//tree" position="attributes">
                    <attribute name="create">true</attribute>
                </xpath>
            </field>
        </record>
        <record id="stock_warehouse_view_search" model="ir.ui.view">
            <field name="name">stock.warehouse.search</field>
            <field name="model">stock.warehouse</field>
            <field name="arch" type="xml">
                <search string="Warehouse">
                    <field name="name"/>
                    <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                </search>
            </field>
        </record>
        <record id="action_warehouse_form" model="ir.actions.act_window">
            <field name="name">Warehouses</field>
            <field name="res_model">stock.warehouse</field>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="view_warehouse_tree"/>
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                Define a new warehouse
              </p>
            </field>
        </record>
        <menuitem action="action_warehouse_form" id="menu_action_warehouse_form"
            parent="menu_warehouse_config" sequence="1"/>

        <!-- Order Point -->
        <record id="view_stock_warehouse_orderpoint_kanban" model="ir.ui.view">
            <field name="name">stock.warehouse.orderpoint.kanban</field>
            <field name="model">stock.warehouse.orderpoint</field>
            <field name="arch" type="xml">
                <kanban class="o_kanban_mobile">
                    <field name="name"/>
                    <field name="product_id"/>
                    <field name="product_min_qty"/>
                    <field name="product_max_qty"/>
                    <templates>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_global_click">
                                <div class="o_kanban_record_top">
                                    <div class="o_kanban_record_headings">
                                        <strong class="o_kanban_record_title"><t t-esc="record.name.value"/></strong>
                                    </div>
                                    <span class="badge badge-pill"><strong>Min qty :</strong><t t-esc="record.product_min_qty.value"/></span>
                                </div>
                                <div class="o_kanban_record_bottom">
                                    <div class="oe_kanban_bottom_left">
                                        <span><t t-esc="record.product_id.value"/></span>
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <span class="badge badge-pill"><strong>Max qty :</strong><t t-esc="record.product_max_qty.value"/></span>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="view_warehouse_orderpoint_tree" model="ir.ui.view">
            <field name="name">stock.warehouse.orderpoint.tree</field>
            <field name="model">stock.warehouse.orderpoint</field>
            <field name="arch" type="xml">
                <tree string="Reordering Rules">
                    <field name="name"/>
                    <field name="active" invisible="1"/>
                    <field name="warehouse_id" groups="stock.group_stock_multi_locations"/>
                    <field name="location_id" groups="stock.group_stock_multi_locations"/>
                    <field name="product_id"/>
                    <field name="product_uom" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom"/>
                    <field name="product_min_qty"/>
                    <field name="product_max_qty"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="warehouse_orderpoint_search">
            <field name="name">stock.warehouse.orderpoint.search</field>
            <field name="model">stock.warehouse.orderpoint</field>
            <field name="arch" type="xml">
                <search string="Reordering Rules Search">
                    <field name="name" string="Reordering Rules"/>
                    <field name="warehouse_id" groups="stock.group_stock_multi_warehouses"/>
                    <field name="location_id" groups="stock.group_stock_multi_locations"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <field name="product_id"/>
                    <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                    <group expand="0" string="Group By">
                        <filter string="Warehouse" name="warehouse" domain="[]"  context="{'group_by':'warehouse_id'}" groups="stock.group_stock_multi_warehouses"/>
                        <filter string="Location" name="location" domain="[]" context="{'group_by':'location_id'}" groups="stock.group_stock_multi_locations"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="view_warehouse_orderpoint_form" model="ir.ui.view">
            <field name="name">stock.warehouse.orderpoint.form</field>
            <field name="model">stock.warehouse.orderpoint</field>
            <field name="arch" type="xml">
                <form string="Reordering Rules">
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
                                <field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
                            </button>
                        </div>
                        <group>
                            <div class="alert alert-info" role="alert">
                                <a style="cursor: pointer" class="alert-link o_form_uri" type="action" name="%(action_procurement_compute)d">Run the scheduler</a> manually to trigger the reordering rules right now.
                            </div>
                        </group>
                        <group>
                            <group>
                                <field name="name" />
                                <field name="product_id"/>
                            </group>
                            <group>
                                <field name="warehouse_id" widget="selection" groups="stock.group_stock_multi_locations"/>
                                <field name="product_uom" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom"/>
                                <field name="location_id" groups="stock.group_stock_multi_locations"/>
                                <field name="group_id" groups="stock.group_adv_location"/>
                                <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
                            </group>
                        </group>
                        <group>
                            <group string="Rules">
                                <field name="product_min_qty"/>
                                <field name="product_max_qty"/>
                                <field name="qty_multiple" string="Quantity Multiple"/>
                            </group>
                            <group string="Misc">
                                <label for="lead_days"/>
                                <div class="o_row">
                                    <field name="lead_days"/>
                                    <field name="lead_type"/>
                                </div>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="action_orderpoint_form" model="ir.actions.act_window">
            <field name="name">Reordering Rules</field>
            <field name="res_model">stock.warehouse.orderpoint</field>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,kanban,form</field>
            <field name="view_id" ref="view_warehouse_orderpoint_tree"/>
            <field name="search_view_id" ref="warehouse_orderpoint_search" />
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                Create a reordering rule
              </p><p>
                Define a minimum stock rule so that Odoo creates automatically requests for quotations or draft manufacturing orders to resupply your stock.
              </p>
            </field>
        </record>
        <menuitem
            id="menu_reordering_rules_config"
            action="action_orderpoint_form"
            name="Reordering Rules" parent="menu_stock_inventory_control" sequence="10"/>

        <act_window
            context="{'search_default_warehouse_id': active_id, 'default_warehouse_id': active_id}"
            id="act_stock_warehouse_2_stock_warehouse_orderpoint"
            name="Reordering Rules"
            res_model="stock.warehouse.orderpoint"
            src_model="stock.warehouse"
            groups="stock.group_stock_user"/>

</odoo>
