<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019-2020 ForgeFlow S.L. (https://www.forgeflow.com)
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="stock_request_order_form_inherit_tier" model="ir.ui.view">
        <field name="name">stock.request.order.tier.validation.form</field>
        <field name="model">stock.request.order</field>
        <field name="inherit_id" ref="stock_request.stock_request_order_form" />
        <field name="arch" type="xml">
            <button name="action_confirm" position="attributes">
                <attribute
                    name="attrs"
                >{'invisible': ['|','&amp;',('validated', '!=', True),('need_validation', '=', True),'|',('need_validation', '=', True),('state', 'not in', ['draft'])]}</attribute>
                <attribute
                    name="groups"
                >stock_request.group_stock_request_manager</attribute>
            </button>
            <button name="action_confirm" position="before">
                <button
                    name="request_validation"
                    string="Request Validation"
                    attrs="{'invisible': ['|','|',('need_validation', '!=', True),('rejected','=',True),('state','not in',['draft','sent'])]}"
                    type="object"
                />
                <button
                    name="restart_validation"
                    string="Restart Validation"
                    attrs="{'invisible': ['|',('review_ids', '=', []),('state','not in',['draft','sent'])]}"
                    type="object"
                />
            </button>
            <header position="after">
                <field name="need_validation" invisible="1" />
                <field name="validated" invisible="1" />
                <field name="rejected" invisible="1" />
                <div
                    class="alert alert-warning"
                    role="alert"
                    attrs="{'invisible': ['|', '|', '|',
                     ('validated', '=', True), ('state', 'not in', ['draft','sent']),
                     ('rejected', '=', True), ('review_ids', '=', [])]}"
                    style="margin-bottom:0px;"
                >
                    <p><i class="fa fa-info-circle" />This Stock Request needs to be
                        validated.
                        <field name="can_review" invisible="1" />
                        <button
                            name="validate_tier"
                            string="Validate"
                            attrs="{'invisible': [('can_review', '=', False)]}"
                            type="object"
                            class="oe_inline oe_button btn-success"
                            icon="fa-thumbs-up"
                        />
                        <button
                            name="reject_tier"
                            string="Reject"
                            attrs="{'invisible': [('can_review', '=', False)]}"
                            type="object"
                            class="btn-icon btn-danger"
                            icon="fa-thumbs-down"
                        />
                    </p>
                </div>
                <div
                    class="alert alert-success"
                    role="alert"
                    attrs="{'invisible': ['|', '|', ('validated', '!=', True), ('state', 'not in', ['draft','sent']), ('review_ids', '=', [])]}"
                    style="margin-bottom:0px;"
                >
                    <p><i class="fa fa-thumbs-up" /> Operation has been <b
                        >validated</b>!</p>
                </div>
                <div
                    class="alert alert-danger"
                    role="alert"
                    attrs="{'invisible': ['|', '|', ('rejected', '!=', True), ('state', 'not in', ['draft','sent']), ('review_ids', '=', [])]}"
                    style="margin-bottom:0px;"
                >
                    <p><i class="fa fa-thumbs-down" /> Operation has been <b
                        >rejected</b>.</p>
                </div>
            </header>
            <xpath expr="//form/div[hasclass('oe_chatter')]" position="before">
                <field
                    name="review_ids"
                    widget="tier_validation"
                    attrs="{'invisible':[('review_ids', '=', [])]}"
                />
            </xpath>
        </field>
    </record>
    <record id="view_stock_request_order_filter" model="ir.ui.view">
        <field name="name">stock.request.select - stock_request_tier_validation</field>
        <field name="model">stock.request</field>
        <field name="inherit_id" ref="stock_request.stock_request_search" />
        <field name="arch" type="xml">
            <search position="inside">
                <group expand="0" string="Need actions">
                    <filter
                        name="needs_review"
                        string="Needs my Review"
                        domain="[('reviewer_ids','in',uid), ('state', 'not in', ['done', 'cancel'])]"
                        help="My Stock Request Orders to review"
                    />
                    <filter
                        name="tier_validated"
                        string="Validated"
                        domain="[('validated', '=', True)]"
                        help="Stock Requests validated and ready to be confirmed"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="tier_review_order_form_wiz" model="ir.ui.view">
        <field name="name">stock.request.order.reviews</field>
        <field name="model">stock.request.order</field>
        <field name="arch" type="xml">
            <form string="Tier Review">
                <group>
                    <field name="review_ids" nolabel="1" readonly="1">
                        <tree
                            create="false"
                            decoration-danger="status=='rejected'"
                            decoration-warning="status=='pending'"
                            decoration-success="status=='approved'"
                        >
                            <field name="sequence" />
                            <field name="requested_by" />
                            <field name="review_type" />
                            <field name="name" />
                            <field name="status" />
                            <field name="done_by" />
                        </tree>
                    </field>
                </group>
                <footer>
                    <button
                        name="dismiss_popup"
                        type="object"
                        string="Dismiss"
                        class="oe_highlight"
                    />
                </footer>
            </form>
        </field>
    </record>
</odoo>
