<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017-18 ForgeFlow S.L.
     License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
    <record id="view_mrp_production_request_form" model="ir.ui.view">
        <field name="name">mrp.production.request.form</field>
        <field name="model">mrp.production.request</field>
        <field name="arch" type="xml">
            <form string="Manufacturing Request">
                <header>
                    <button
                        groups="mrp_production_request.group_mrp_production_request_manager"
                        name="button_draft"
                        states="to_approve,approved,cancel,done"
                        string="Reset"
                        type="object"
                    />
                    <button
                        class="oe_highlight"
                        name="button_to_approve"
                        states="draft"
                        string="Request approval"
                        type="object"
                    />
                    <button
                        class="oe_highlight"
                        groups="mrp_production_request.group_mrp_production_request_manager"
                        name="button_approved"
                        states="to_approve"
                        string="Approve"
                        type="object"
                    />
                    <button
                        name="%(mrp_production_request_create_mo_action)d"
                        states="approved"
                        string="Create Manufacturing Order"
                        type="action"
                    />
                    <button
                        class="oe_highlight"
                        groups="mrp_production_request.group_mrp_production_request_manager"
                        name="button_done"
                        states="approved"
                        string="Done"
                        type="object"
                    />
                    <button
                        groups="mrp_production_request.group_mrp_production_request_manager"
                        name="button_cancel"
                        states="to_approve,approved"
                        string="Reject"
                        type="object"
                    />
                    <field
                        name="state"
                        statusbar_visible="draft,approved,done"
                        widget="statusbar"
                    />
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button
                            attrs="{'invisible': [('mrp_production_count', '=', 0)]}"
                            class="oe_stat_button"
                            icon="fa-wrench"
                            name="action_view_mrp_productions"
                            type="object"
                        >
                            <field
                                name="mrp_production_count"
                                string="MOs"
                                widget="statinfo"
                            />
                        </button>
                    </div>
                    <label for="name" string="Manufacturing Request" />
                    <h1>
                        <field name="name" />
                    </h1>
                    <group name="request">
                        <group>
                            <field
                                domain="[('bom_ids','!=',False),('bom_ids.type','!=','phantom')]"
                                name="product_id"
                            />
                            <field invisible="1" name="product_tmpl_id" />
                            <field
                                domain="['&amp;', '|', ('product_id','=',product_id),                                '&amp;', ('product_tmpl_id.product_variant_ids','=',product_id),                                ('product_id','=',False), ('type', '=', 'normal')]"
                                name="bom_id"
                            />
                        </group>
                        <group>
                            <field name="product_qty" />
                            <field name="done_qty" />
                            <field name="manufactured_qty" />
                            <field name="pending_qty" />
                            <field groups="uom.group_uom" name="product_uom_id" />
                            <field invisible="1" name="category_uom_id" />
                        </group>
                    </group>
                    <group>
                        <group name="users">
                            <field name="requested_by" />
                            <field name="assigned_to" />
                        </group>
                        <group name="dates">
                            <field name="date_planned_start" />
                            <field name="date_planned_finished" />
                        </group>
                    </group>
                    <notebook>
                        <page name="mrp_production" string="Manufacturing Orders">
                            <field name="mrp_production_ids" />
                        </page>
                        <page name="extra" string="Extra information">
                            <group>
                                <group>
                                    <field name="location_src_id" />
                                    <field name="location_dest_id" />
                                    <field name="picking_type_id" />
                                </group>
                                <group>
                                    <field name="origin" />
                                    <field name="description" />
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" />
                    <field name="message_ids" widget="mail_thread" />
                </div>
            </form>
        </field>
    </record>
    <record id="view_mrp_production_request_tree" model="ir.ui.view">
        <field name="name">mrp.production.request.tree</field>
        <field name="model">mrp.production.request</field>
        <field name="arch" type="xml">
            <tree
                decoration-info="state in ('draft','to_approve')"
                decoration-muted="state in ('cancel')"
                string="Manufacturing Requests"
            >
                <field name="name" />
                <field name="product_id" />
                <field name="requested_by" />
                <field name="assigned_to" />
                <field name="product_qty" />
                <field name="pending_qty" />
                <field
                    groups="base.group_multi_company"
                    name="company_id"
                    widget="selection"
                />
                <field name="origin" />
                <field name="date_planned_start" />
                <field name="state" />
            </tree>
        </field>
    </record>
    <record id="view_mrp_production_request_search" model="ir.ui.view">
        <field name="name">mrp.production.request.search</field>
        <field name="model">mrp.production.request</field>
        <field name="arch" type="xml">
            <search string="Search Manufacturing Request">
                <field name="name" string="Manufacturing Request" />
                <field name="product_id" />
                <field name="mrp_production_ids" string="Manufacturing Orders" />
                <field name="bom_id" />
                <field name="requested_by" />
                <field name="assigned_to" />
                <field name="origin" />
                <field name="state" />
                <field invisible="1" name="pending_qty" />
                <!--Filters:-->
                <filter
                    domain="[('assigned_to','=', False)]"
                    help="Unassigned Request"
                    name="unassigned"
                    string="Unassigned"
                />
                <filter
                    domain="[('assigned_to','=', uid)]"
                    name="assigned_to_me"
                    string="Assigned to me"
                />
                <filter
                    domain="[('requested_by','=', uid)]"
                    help="Requested by me"
                    name="requested_by_me"
                    string="My requests"
                />
                <separator />
                <filter
                    domain="[('pending_qty','!=', 0.0)]"
                    help="Request with pending quantity"
                    name="pending"
                    string="Pending Qty"
                />
                <separator />
                <filter
                    domain="[('state','in',('draft', 'to_approve','approved'))]"
                    help="Manufacturing Requests not done or cancelled."
                    name="todo"
                    string="To Do"
                />
                <separator />
                <filter
                    domain="[('state','=','draft')]"
                    help="Request is to be approved"
                    name="state_draft"
                    string="Draft"
                />
                <filter
                    domain="[('state','=','to_approve')]"
                    help="Request is to be approved"
                    name="state_to_approve"
                    string="To Approve"
                />
                <filter
                    domain="[('state','=','approved')]"
                    help="Request is approved"
                    name="state_approved"
                    string="Approved"
                />
                <filter
                    domain="[('state','=','cancel')]"
                    help="Request is cancelled"
                    name="state_cancel"
                    string="Cancelled"
                />
                <filter
                    domain="[('state','=','done')]"
                    help="Request is done"
                    name="state_done"
                    string="Done"
                />
                <separator />
                <filter
                    domain="[('message_needaction','=',True)]"
                    name="message_needaction"
                    string="Unread Messages"
                />
                <!--Group by:-->
                <filter
                    context="{'group_by':'requested_by'}"
                    domain="[]"
                    icon="terp-personal"
                    name="requested_by_group_by"
                    string="Requested by"
                />
                <filter
                    context="{'group_by':'assigned_to'}"
                    domain="[]"
                    icon="terp-personal"
                    name="assign_to_group_by"
                    string="Assigned to"
                />
                <filter
                    context="{'group_by':'origin'}"
                    domain="[]"
                    name="origin_group_by"
                    string="Source"
                />
            </search>
        </field>
    </record>
    <record id="mrp_production_request_action" model="ir.actions.act_window">
        <field name="name">Manufacturing Requests</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">mrp.production.request</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{&quot;search_default_todo&quot;:1}</field>
        <field name="help" type="html">
            <p
                class="oe_view_nocontent_create"
            >Click to start a new manufacturing request process.
          </p>
            <p>A Manufacturing Request is an instruction to production to produce
            a certain quantity of a given product.
          </p>
        </field>
    </record>
    <menuitem
        action="mrp_production_request_action"
        id="menu_mrp_production_request_act"
        parent="mrp.menu_mrp_manufacturing"
        sequence="10"
    />
    <!--Sever actions-->
    <record id="action_server_mrp_production_request_refresh" model="ir.actions.server">
        <field name="name">Refresh Quantities</field>
        <field name="model_id" ref="model_mrp_production_request" />
        <field name="binding_model_id" ref="model_mrp_production_request" />
        <field name="state">code</field>
        <field name="code">records._compute_manufactured_qty()</field>
    </record>
</odoo>
