<?xml version="1.0" ?>
<!-- Copyright 2018-2019 ForgeFlow, S.L.
     License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
    <record id="purchase_request_line_tree" model="ir.ui.view">
        <field name="name">purchase.request.line.tree</field>
        <field name="model">purchase.request.line</field>
        <field name="arch" type="xml">
            <tree
                name="Purchase Request Lines"
                create="false"
                decoration-muted="cancelled == True"
                decoration-info="request_state in ('draft', 'to_approve')"
            >
                <field name="request_id" />
                <field
                    name="request_state"
                    widget="badge"
                    decoration-success="request_state in ('done', 'approved', 'in_progress')"
                    decoration-info="request_state in ('draft', 'to_approve')"
                    decoration-danger="request_state == 'rejected'"
                />
                <field name="requested_by" widget="many2one_avatar_user" />
                <field name="assigned_to" widget="many2one_avatar_user" />
                <field name="date_required" />
                <field name="estimated_cost" widget="monetary" />
                <field name="currency_id" invisible="1" />
                <field name="purchased_qty" />
                <field
                    name="purchase_state"
                    widget="badge"
                    decoration-success="purchase_state == 'done'"
                    decoration-muted="purchase_state == 'draft'"
                    decoration-info="purchase_state in ('sent', 'purchase')"
                    decoration-warning="purchase_state == 'to_approve'"
                    decoration-danger="purchase_state == 'cancelled'"
                />
                <field name="product_id" />
                <field name="name" />
                <field name="product_qty" />
                <field name="product_uom_category_id" invisible="1" />
                <field name="product_uom_id" groups="uom.group_uom" />
                <field
                    name="analytic_distribution"
                    widget="analytic_distribution"
                    optional="hide"
                    groups="analytic.group_analytic_accounting"
                    options="{'product_field': 'product_id', 'business_domain': 'purchase_order'}"
                />
                <field name="supplier_id" />
                <field
                    name="company_id"
                    groups="base.group_multi_company"
                    widget="selection"
                />
                <field name="cancelled" invisible="1" />
                <field name="qty_in_progress" invisible="1" />
                <field name="qty_done" invisible="1" />
                <field name="qty_cancelled" invisible="1" />
            </tree>
        </field>
    </record>
    <record id="purchase_request_line_form" model="ir.ui.view">
        <field name="name">purchase.request.line.form</field>
        <field name="model">purchase.request.line</field>
        <field name="priority" eval="20" />
        <field name="arch" type="xml">
            <form string="Purchase Request Line" create="false" duplicate="false">
                <header>
                    <field
                        name="request_state"
                        widget="statusbar"
                        statusbar_visible="draft,to_approve,approved,done,in_progress"
                    />
                </header>
                <sheet>
                    <h1>
                        <field name="request_id" />
                    </h1>
                    <group name="main">
                        <group name="info">
                            <field
                                name="origin"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="requested_by"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="assigned_to"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="description"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="date_start"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="company_id"
                                groups="base.group_multi_company"
                                widget="selection"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field name="is_editable" invisible="1" />
                        </group>
                        <group name="settings">
                            <field
                                name="product_id"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="name"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <label for="product_qty" />
                            <div>
                                <field
                                    name="product_qty"
                                    class="oe_inline"
                                    attrs="{'readonly': [('is_editable','=', False)]}"
                                />
                                <field name="product_uom_category_id" invisible="1" />
                                <field
                                    name="product_uom_id"
                                    groups="uom.group_uom"
                                    class="oe_inline"
                                    attrs="{'readonly': [('is_editable','=', False)]}"
                                />
                            </div>
                            <field
                                name="analytic_distribution"
                                widget="analytic_distribution"
                                groups="analytic.group_analytic_accounting"
                                options="{'product_field': 'product_id', 'business_domain': 'purchase_order'}"
                            />
                            <field
                                name="date_required"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field
                                name="estimated_cost"
                                widget="monetary"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                            <field name="currency_id" invisible="1" />
                            <field name="cancelled" />
                        </group>
                    </group>
                    <group name="specifications">
                        <separator string="Specifications" />
                        <newline />
                        <field
                            name="specifications"
                            nolabel="1"
                            attrs="{'readonly': [('is_editable','=', False)]}"
                        />
                    </group>
                    <group name="quantities" string="Tracking">
                        <group>
                            <field name="pending_qty_to_receive" />
                            <field name="qty_in_progress" />
                            <field name="qty_done" />
                            <field name="qty_cancelled" />
                        </group>
                    </group>
                    <notebook>
                        <page name="purchase_lines" string="Purchase Order Lines">
                            <group>
                                <field name="purchased_qty" />
                                <field name="purchase_state" />
                            </group>
                            <field
                                name="purchase_lines"
                                mode="tree"
                                attrs="{'readonly': [('purchase_state', 'in', ('cancel'))]}"
                                domain="[('product_id', '=', product_id)]"
                                context="{'form_view_ref' : 'purchase_request.purchase_order_line_form2_sub',
                                             'tree_view_ref' : 'purchase_request.purchase_order_line_tree_sub',
                                             'search_view_ref' : 'purchase_request.purchase_order_line_search_sub'}"
                            />
                        </page>
                        <page name="allocations" string="Allocations">
                            <field name="purchase_request_allocation_ids">
                                <tree decoration-muted="purchase_state == 'cancel'">
                                    <field name="purchase_line_id" />
                                    <field name="stock_move_id" />
                                    <field name="product_id" />
                                    <field name="requested_product_uom_qty" />
                                    <field name="allocated_product_qty" />
                                    <field name="open_product_qty" />
                                    <field name="product_uom_id" />
                                    <field name="purchase_state" invisible="1" />
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" />
                    <field name="activity_ids" widget="mail_activity" />
                    <field name="message_ids" widget="mail_thread" />
                </div>
            </form>
        </field>
    </record>
    <record id="purchase_request_line_search" model="ir.ui.view">
        <field name="name">purchase.request.line.search</field>
        <field name="model">purchase.request.line</field>
        <field name="arch" type="xml">
            <search string="Search Purchase Request">
                <field name="request_id" />
                <field name="product_id" />
                <field name="requested_by" />
                <field name="assigned_to" />
                <field name="date_start" />
                <field name="date_required" />
                <filter
                    name="purchase_state_none"
                    string="Purchasing not started"
                    domain="[('purchase_state','=', False)]"
                    help="No RFQ or Purchase has been created"
                />
                <filter
                    name="purchase_state_draft"
                    string="Requested for Quotation"
                    domain="[('purchase_state','=','draft')]"
                    help="At least a Draft PO has been created"
                />
                <filter
                    name="purchase_state_confirmed"
                    string="Purchase Confirmed"
                    domain="[('purchase_state','=','confirmed')]"
                    help="At least a PO has been confirmed"
                />
                <filter
                    name="purchase_state_done"
                    string="Purchase Done"
                    domain="[('purchase_state','=','done')]"
                    help="At least a PO has been completed"
                />
                <field
                    name="analytic_distribution"
                    groups="analytic.group_analytic_accounting"
                />
                <field name="cancelled" invisible="1" />
                <filter
                    name="request_state_draft"
                    string="Draft"
                    domain="[('request_state','=','draft')]"
                    help="Request is to be approved"
                />
                <filter
                    name="request_state_to_approve"
                    string="To Approve"
                    domain="[('request_state','=','to_approve')]"
                    help="Request is to be approved"
                />
                <filter
                    name="request_state_approved"
                    string="Approved"
                    domain="[('request_state','=','approved')]"
                    help="Request is approved"
                />
                <filter
                    name="request_state_rejected"
                    string="Rejected"
                    domain="[('request_state','=','rejected')]"
                    help="Request is rejected"
                />
                <filter
                    name="request_state_in_progress"
                    string="In Progress"
                    domain="[('request_state','=','in_progress')]"
                    help="Request is in progress"
                />
                <filter
                    name="assigned_to_me"
                    domain="[( 'assigned_to','=', uid)]"
                    help="Assigned to me"
                />
                <filter
                    name="my_requests"
                    domain="[('requested_by','=', uid)]"
                    help="My requests"
                />
                <filter
                    name="uncancelled"
                    domain="[('cancelled','=', False)]"
                    string="Uncancelled"
                />
                <filter
                    name="qty_to_buy"
                    string="Pending Qty to Receive"
                    domain="[('qty_to_buy','=',True)]"
                />
                <filter
                    name="all_bought"
                    string="All Bought"
                    domain="[('qty_to_buy','=',False)]"
                />
                <filter
                    name="open"
                    domain="[('qty_in_progress','!=', 0.0)]"
                    string="Open Quantity"
                />
                <filter
                    name="cancel"
                    domain="[('qty_cancelled','>', 0.0)]"
                    string="Cancelled Quantity"
                />
                <group expand="0" string="Group By...">
                    <filter
                        name="product"
                        string="Product"
                        domain="[]"
                        context="{'group_by' : 'product_id'}"
                    />
                    <filter
                        name="requested_by"
                        string="Requested by"
                        domain="[]"
                        context="{'group_by':'requested_by'}"
                    />
                    <filter
                        name="assigned_to"
                        string="Assigned to"
                        domain="[]"
                        context="{'group_by':'assigned_to'}"
                    />
                    <filter
                        name="request_status"
                        string="Request status"
                        domain="[]"
                        context="{'group_by':'request_state'}"
                    />
                    <filter
                        name="group_analytic_distribution"
                        string="Analytic Distribution"
                        domain="[]"
                        context="{'group_by':'analytic_distribution'}"
                        groups="analytic.group_analytic_accounting"
                    />
                    <filter
                        name="purchase_status"
                        string="Purchase Status"
                        domain="[]"
                        context="{'group_by':'purchase_state'}"
                    />
                    <filter
                        name="request"
                        string="Request"
                        domain="[]"
                        context="{'group_by':'request_id'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <record
        id="action_purchase_request_line_product_tree"
        model="ir.actions.act_window"
    >
        <field name="context">
            {'search_default_product_id': [active_id], 'default_product_id': active_id}
        </field>
        <field name="name">Purchase Requests</field>
        <field name="res_model">purchase.request.line</field>
        <field name="binding_model_id" ref="product.model_product_product" />
        <field
            name="groups_id"
            eval="[(4, ref('purchase_request.group_purchase_request_user')),(4, ref('purchase_request.group_purchase_request_manager'))]"
        />
    </record>
    <record id="purchase_request_line_form_action" model="ir.actions.act_window">
        <field name="name">Purchase Request Lines</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">purchase.request.line</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="purchase_request_line_search" />
    </record>
    <record
        id="purchase_request_line_form_action_tree"
        model="ir.actions.act_window.view"
    >
        <field eval="1" name="sequence" />
        <field name="view_mode">tree</field>
        <field name="view_id" ref="purchase_request_line_tree" />
        <field name="act_window_id" ref="purchase_request_line_form_action" />
    </record>
    <record
        id="purchase_request_line_form_action_form2"
        model="ir.actions.act_window.view"
    >
        <field eval="2" name="sequence" />
        <field name="view_mode">form</field>
        <field name="view_id" ref="purchase_request_line_form" />
        <field name="act_window_id" ref="purchase_request_line_form_action" />
    </record>
    <record id="purchase_order_line_form2_sub" model="ir.ui.view">
        <field name="name">purchase.order.line.form2</field>
        <field name="model">purchase.order.line</field>
        <field name="arch" type="xml">
            <form string="Purchase Order Lines" create="false" readonly="1">
                <sheet>
                    <label for="order_id" readonly="1" class="oe_edit_only" />
                    <h1>
                        <field name="order_id" readonly="1" class="oe_inline" />
                        <label
                            for="date_order"
                            string=","
                            readonly="1"
                            attrs="{'invisible':[('date_order','=',False)]}"
                        />
                        <field name="date_order" readonly="1" class="oe_inline" />
                    </h1>
                    <label for="partner_id" readonly="1" class="oe_edit_only" />
                    <h2>
                        <field name="partner_id" readonly="1" />
                    </h2>
                    <group>
                        <group>
                            <field name="product_id" readonly="1" />
                            <label for="product_qty" readonly="1" />
                            <div>
                                <field
                                    name="product_qty"
                                    readonly="1"
                                    class="oe_inline"
                                />
                                <field
                                    name="product_uom"
                                    readonly="1"
                                    groups="uom.group_uom"
                                    class="oe_inline"
                                />
                                <field name="product_uom_category_id" invisible="1" />
                            </div>
                            <field name="price_unit" widget="monetary" readonly="1" />
                        </group>
                        <group>
                            <field
                                name="taxes_id"
                                widget="many2many_tags"
                                domain="[('type_tax_use', '=', 'purchase')]"
                                readonly="1"
                            />
                            <field name="date_planned" widget="date" readonly="1" />
                            <field
                                name="company_id"
                                readonly="1"
                                groups="base.group_multi_company"
                                options="{'no_create': True}"
                            />
                            <field
                                name="analytic_distribution"
                                widget="analytic_distribution"
                                groups="analytic.group_analytic_accounting"
                                options="{'product_field': 'product_id', 'business_domain': 'purchase_order'}"
                                colspan="4"
                            />
                        </group>
                    </group>
                    <field name="name" readonly="1" />
                    <separator string="Manual Invoices" />
                    <field name="invoice_lines" readonly="1" />
                    <separator string="Stock Moves" />
                    <field name="move_ids" readonly="1" />
                    <separator string="Purchase Request Lines" />
                    <field name="purchase_request_lines" readonly="1" />
                </sheet>
            </form>
        </field>
    </record>
    <record id="purchase_order_line_tree_sub" model="ir.ui.view">
        <field name="name">purchase.order.line.tree</field>
        <field name="model">purchase.order.line</field>
        <field name="arch" type="xml">
            <tree name="Purchase Order Lines" create="true">
                <field name="order_id" />
                <field name="name" />
                <field name="partner_id" string="Vendor" />
                <field name="product_id" />
                <field name="price_unit" />
                <field name="product_qty" />
                <field name="product_uom" groups="uom.group_uom" />
                <field name="price_subtotal" widget="monetary" />
                <field name="date_planned" widget="date" />
                <field name="purchase_request_lines" invisible="1" />
            </tree>
        </field>
    </record>
    <record id="purchase_order_line_search_sub" model="ir.ui.view">
        <field name="name">purchase.order.line.search</field>
        <field name="model">purchase.order.line</field>
        <field name="arch" type="xml">
            <search string="Search Purchase Order Line">
                <field name="order_id" />
                <field name="product_id" />
                <field
                    name="partner_id"
                    string="Vendor"
                    filter_domain="[('partner_id', 'child_of', self)]"
                />
                <filter
                    name="hide_cancelled"
                    string="Hide cancelled lines"
                    domain="[('state', '!=', 'cancel')]"
                />
                <group expand="0" string="Group By">
                    <filter
                        name="order_reference"
                        string="Order Reference"
                        domain="[]"
                        context="{'group_by': 'order_id'}"
                    />
                    <filter
                        name="groupby_supplier"
                        string="Vendor"
                        domain="[]"
                        context="{'group_by': 'partner_id'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="view_purchase_request_line_details" model="ir.ui.view">
        <field name="name">purchase.request.line.details.form</field>
        <field name="model">purchase.request.line</field>
        <field name="priority">1000</field>
        <field name="arch" type="xml">
        <form>
            <sheet>
                <group name="main">
                    <group>
                        <field name="is_editable" invisible="1" />
                        <field
                                name="product_id"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                        <field
                                name="name"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                        <label for="product_qty" />
                        <div class="o_row">
                            <field
                                    name="product_qty"
                                    class="oe_inline"
                                    attrs="{'readonly': [('is_editable','=', False)]}"
                                />
                            <field name="product_uom_category_id" invisible="1" />
                            <field
                                    name="product_uom_id"
                                    groups="uom.group_uom"
                                    class="oe_inline"
                                    attrs="{'readonly': [('is_editable','=', False)]}"
                                />
                        </div>
                        <field
                                name="analytic_distribution"
                                widget="analytic_distribution"
                                groups="analytic.group_analytic_accounting"
                                options="{'product_field': 'product_id', 'business_domain': 'purchase_order'}"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                        <field
                                name="date_required"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                        <field
                                name="estimated_cost"
                                widget="monetary"
                                attrs="{'readonly': [('is_editable','=', False)]}"
                            />
                        <field name="currency_id" invisible="1" />
                        <field name="cancelled" widget="boolean" />
                    </group>
                </group>
                <group name="specifications">
                    <separator string="Specifications" />
                    <newline />
                    <field
                            name="specifications"
                            nolabel="1"
                            attrs="{'readonly': [('is_editable','=', False)]}"
                        />
                </group>
                <group name="quantities" string="Tracking">
                    <group>
                        <field name="pending_qty_to_receive" />
                        <field name="qty_in_progress" />
                        <field name="qty_done" />
                        <field name="qty_cancelled" />
                    </group>
                </group>
                <notebook>
                    <page name="purchase_lines" string="Purchase Order Lines">
                        <group>
                            <group name="purchase_state">
                                <field name="purchased_qty" />
                                <field name="purchase_state" />
                                <field name="qty_in_progress" />
                                <field name="qty_done" />
                            </group>
                        </group>
                        <field name="purchase_lines" nolabel="1" />
                    </page>
                </notebook>
            </sheet>
        </form>
        </field>
    </record>
    <menuitem
        action="purchase_request_line_form_action"
        id="menu_purchase_request_line"
        parent="purchase.menu_procurement_management"
    />
    <menuitem
        id="menu_purchase_request_line_act"
        sequence="20"
        parent="menu_purchase_request"
        action="purchase_request_line_form_action"
    />
</odoo>
