<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2010 NaN Projectes de Programari Lliure, S.L.
    Copyright 2014 Serv. Tec. Avanzados - Pedro M. Baeza
    Copyright 2014 Oihane Crucelaegui - AvanzOSC
    Copyright 2017 ForgeFlow S.L.
    Copyright 2017 Simone Rubino - Agile Business Group
    License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record model="ir.ui.view" id="qc_inspection_form_view">
        <field name="name">qc.inspection.form</field>
        <field name="model">qc.inspection</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button
                        name="action_draft"
                        type="object"
                        attrs="{'invisible': [('state', '!=', 'canceled')]}"
                        string="Draft"
                    />
                    <button
                        name="action_todo"
                        type="object"
                        class="oe_highlight"
                        states="draft"
                        string="Mark todo"
                    />
                    <button
                        name="action_confirm"
                        type="object"
                        class="oe_highlight"
                        states="ready"
                        string="Confirm"
                        icon="fa-check"
                    />
                    <button
                        name="action_approve"
                        type="object"
                        states="waiting"
                        class="oe_highlight"
                        groups="quality_control_oca.group_quality_control_manager"
                        string="Approve"
                    />
                    <button
                        name="action_cancel"
                        type="object"
                        attrs="{'invisible': [('state', 'not in', ['waiting', 'ready', 'failed', 'success'])]}"
                        string="Cancel"
                        icon="fa-ban"
                    />
                    <field
                        name="state"
                        widget="statusbar"
                        statusbar_visible="draft,waiting,success"
                    />
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button
                            class="oe_stat_button"
                            type="action"
                            name="%(action_qc_inspection_set_test)d"
                            icon="fa-bookmark-o"
                            states="draft"
                            string="Set test"
                        />
                    </div>
                    <h1>
                        <label string="Inspection " for="name" />
                        <field name="name" class="oe_inline" />
                    </h1>
                    <group>
                        <group>
                            <field name="test" />
                            <field name="user" />
                            <field name="object_id" />
                            <field name="qty" />
                            <field name="product_id" />
                        </group>
                        <group>
                            <field name="date" />
                            <field name="date_done" />
                            <field name="success" />
                            <field name="auto_generated" />
                        </group>
                    </group>
                    <notebook>
                        <page string="Questions">
                            <field
                                name="inspection_lines"
                                nolabel="1"
                                mode="tree,kanban"
                            >
                                <tree editable="top" delete="false" create="false">
                                    <field name="name" />
                                    <field name="question_type" optional="show" />
                                    <field name="possible_ql_values" invisible="1" />
                                    <field
                                        name="qualitative_value"
                                        attrs="{'readonly': [('question_type', '=', 'quantitative')]}"
                                        options="{'no_create': True, 'no_create_edit':True}"
                                    />
                                    <field
                                        name="quantitative_value"
                                        attrs="{'readonly': [('question_type', '=', 'qualitative')]}"
                                    />
                                    <field
                                        name="uom_id"
                                        groups="uom.group_uom"
                                        attrs="{'readonly': [('question_type', '=', 'qualitative')]}"
                                    />
                                    <field name="test_uom_category" invisible="1" />
                                    <field name="min_value" invisible="1" />
                                    <field name="max_value" invisible="1" />
                                    <field name="valid_values" optional="show" />
                                    <field name="success" />
                                </tree>
                            </field>
                        </page>
                        <page string="Notes">
                            <group string="Internal notes">
                                <field name="internal_notes" nolabel="1" colspan="2" />
                            </group>
                            <group string="External notes">
                                <field name="external_notes" nolabel="1" colspan="2" />
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field
                        name="message_follower_ids"
                        widget="mail_followers"
                        groups="base.group_user"
                    />
                    <field name="message_ids" widget="mail_thread" />
                </div>
            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="qc_inspection_tree_view">
        <field name="name">qc.inspection.tree</field>
        <field name="model">qc.inspection</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name" />
                <field name="user" />
                <field name="test" />
                <field name="qty" />
                <field name="product_id" />
                <field name="date" optional="show" />
                <field name="date_done" optional="show" />
                <field name="success" />
                <field
                    name="state"
                    widget="badge"
                    decoration-info="state == 'ready'"
                    decoration-warning="state == 'waiting'"
                    decoration-success="state == 'success'"
                    decoration-danger="state == 'failed'"
                    decoration-muted="state == 'canceled'"
                />
            </tree>
        </field>
    </record>
    <record model="ir.ui.view" id="qc_inspection_kanban_view">
        <field name="name">qc.inspection.kanban</field>
        <field name="model">qc.inspection</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile">
                <field name="name" />
                <field name="product_id" />
                <field name="qty" />
                <field name="date" />
                <field name="test" />
                <field name="state" />
                <field name="success" />
                <progressbar
                    field="activity_state"
                    colors="{&quot;planned&quot;: &quot;success&quot;, &quot;today&quot;: &quot;warning&quot;, &quot;overdue&quot;: &quot;danger&quot;}"
                />
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_card oe_kanban_global_click">
                            <div class="o_kanban_record_top">
                                <div class="o_kanban_record_headings mt4 ms-1">
                                  <strong class="o_kanban_record_title"><span><t
                                                t-esc="record.product_id.value"
                                            /></span></strong>
                                  <div class="o_kanban_record_subtitle">
                                      <span><t t-esc="record.test.value" /></span>
                                  </div>
                                </div>
                                <span class="float-end text-end"><t
                                        t-esc="record.qty.value"
                                    /></span>
                            </div>
                            <div class="o_kanban_record_bottom">
                                <div class="oe_kanban_bottom_left text-muted">
                                    <span><t t-esc="record.name.value" /> <t
                                            t-esc="record.date.value and record.date.value.split(' ')[0] or False"
                                        /></span>
                                    <field
                                        name="activity_ids"
                                        widget="kanban_activity"
                                    />
                                </div>
                                <div class="oe_kanban_bottom_right">
                                  <div
                                        class="me-2"
                                        attrs="{'invisible': [('state', 'in', ['success', 'failed'])]}"
                                    >
                                      <i
                                            t-if="record.success.raw_value == 1"
                                            class="fa fa-check text-success"
                                            role="img"
                                            aria-label="Success"
                                        />
                                      <i
                                            t-else=""
                                            class="fa fa-times text-danger"
                                            role="img"
                                            aria-label="Failed"
                                        />
                                    </div>
                                    <span
                                        t-attf-class="badge #{['canceled'].indexOf(record.state.raw_value) &gt; -1 ? 'bg-light' : ['draft'].indexOf(record.state.raw_value) &gt; -1 ? 'bg-200' : ['waiting'].indexOf(record.state.raw_value) &gt; -1 ? 'bg-warning' : ['success'].indexOf(record.state.raw_value) &gt; -1 ? 'bg-success text-white' : ['failed'].indexOf(record.state.raw_value) &gt; -1 ? 'bg-danger text-white' : 'bg-primary'}"
                                    ><t t-esc="record.state.value" /></span>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>
    <record model="ir.ui.view" id="qc_inspection_search_view">
        <field name="name">qc.inspection.search</field>
        <field name="model">qc.inspection</field>
        <field name="arch" type="xml">
            <search string="Search inspection">
                <group>
                    <field name="name" />
                    <field name="user" />
                    <field name="object_id" />
                    <field name="product_id" />
                    <field name="test" />
                </group>
                <newline />
                <filter
                    string="Correct"
                    name="correct"
                    domain="[('success', '=', True)]"
                />
                <filter
                    string="Incorrect"
                    name="incorrect"
                    domain="[('success', '=', False)]"
                />
                <newline />
                <separator />
                <filter name="plan_date" string="Plan Date" date="date" />
                <filter name="date_done" string="Completion Date" date="date_done" />
                <group expand="0" string="Group by...">
                    <filter
                        string="Reference"
                        name="group_by_object_id"
                        domain="[]"
                        context="{'group_by': 'object_id'}"
                    />
                    <filter
                        string="Test"
                        name="group_by_test"
                        domain="[]"
                        context="{'group_by': 'test'}"
                    />
                    <filter
                        string="Responsible"
                        name="group_by_user"
                        domain="[]"
                        context="{'group_by': 'user'}"
                    />
                    <filter
                        string="Product"
                        name="group_by_product_id"
                        domain="[]"
                        context="{'group_by': 'product_id'}"
                    />
                    <filter
                        string="State"
                        name="group_by_state"
                        domain="[]"
                        context="{'group_by': 'state'}"
                    />
                    <filter
                        string="Success"
                        name="group_by_success"
                        domain="[]"
                        context="{'group_by': 'success'}"
                    />
                    <filter
                        string="Auto-generated"
                        name="group_by_auto_generated"
                        domain="[]"
                        context="{'group_by': 'auto_generated'}"
                    />
                    <filter
                        string="Plan Date"
                        name="groupby_date"
                        domain="[]"
                        context="{'group_by': 'date'}"
                    />
                    <filter
                        string="Completion Date"
                        name="groupby_date_done"
                        domain="[]"
                        context="{'group_by': 'date_done'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_qc_inspection">
        <field name="name">Inspections</field>
        <field name="res_model">qc.inspection</field>
        <field name="view_mode">tree,form,kanban</field>
    </record>
    <menuitem
        name="Inspections"
        parent="qc_inspection_menu_parent"
        id="qc_inspection_menu"
        action="action_qc_inspection"
    />
    <record model="ir.ui.view" id="qc_inspection_line_tree_view">
        <field name="name">qc.inspection.line.tree</field>
        <field name="model">qc.inspection.line</field>
        <field name="arch" type="xml">
            <tree
                decoration-danger="success==False"
                decoration-info="success==True"
                delete="false"
                create="false"
            >
                <field name="inspection_id" />
                <field name="product_id" />
                <field name="name" />
                <field name="question_type" />
                <field name="possible_ql_values" invisible="1" />
                <field
                    name="qualitative_value"
                    attrs="{'readonly': [('question_type', '=', 'quantitative')]}"
                />
                <field
                    name="quantitative_value"
                    attrs="{'readonly': [('question_type', '=', 'qualitative')]}"
                />
                <field
                    name="uom_id"
                    groups="uom.group_uom"
                    attrs="{'readonly': [('question_type', '=', 'qualitative')]}"
                />
                <field name="test_uom_category" invisible="1" />
                <field name="valid_values" />
                <field name="success" />
            </tree>
        </field>
    </record>
    <record model="ir.ui.view" id="qc_inspection_line_kanban_view">
        <field name="name">qc.inspection.line.kanban</field>
        <field name="model">qc.inspection.line</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile">
                <field name="name" />
                <field name="product_id" />
                <field name="question_type" />
                <field name="qualitative_value" />
                <field name="quantitative_value" />
                <field name="success" />
                <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"><span><field
                                                name="name"
                                            /></span></strong>
                                </div>
                            </div>
                            <div class="o_kanban_record_body">
                              <span><field name="product_id" /></span>
                            </div>
                            <div class="o_kanban_record_bottom">
                              <div class="oe_kanban_bottom_left">
                                <field
                                        t-if="record.question_type.raw_value == 'qualitative'"
                                        name="qualitative_value"
                                    />
                                <span
                                        t-elif="record.question_type.raw_value == 'quantitative'"
                                    ><field name="quantitative_value" /> <field
                                            name="uom_id"
                                        /></span>
                              </div>
                              <div class="oe_kanban_bottom_right">
                                      <i
                                        t-if="record.success.raw_value == 1"
                                        class="fa fa-check text-success"
                                        role="img"
                                        aria-label="Success"
                                    />
                                      <i
                                        t-else=""
                                        class="fa fa-times text-danger"
                                        role="img"
                                        aria-label="Failed"
                                    />
                              </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>
    <record model="ir.ui.view" id="qc_inspection_line_search_view">
        <field name="name">qc.inspection.line.search</field>
        <field name="model">qc.inspection.line</field>
        <field name="arch" type="xml">
            <search string="Search inspection line">
                <group>
                    <field name="name" />
                    <field name="inspection_id" />
                    <field name="product_id" />
                    <field name="success" />
                </group>
                <newline />
                <filter
                    string="Correct"
                    name="correct"
                    domain="[('success', '=', True)]"
                />
                <filter
                    string="Incorrect"
                    name="incorrect"
                    domain="[('success', '=', False)]"
                />
                <newline />
                <group expand="0" string="Group by...">
                    <filter
                        string="Inspection"
                        name="group_by_inspection_id"
                        domain="[]"
                        context="{'group_by': 'inspection_id'}"
                    />
                    <filter
                        string="Product"
                        name="group_by_product_id"
                        domain="[]"
                        context="{'group_by': 'product_id'}"
                    />
                    <filter
                        string="Question"
                        name="group_by_name"
                        domain="[]"
                        context="{'group_by': 'name'}"
                    />
                    <filter
                        string="Success"
                        name="group_by_success"
                        domain="[]"
                        context="{'group_by': 'success'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_qc_inspection_line">
        <field name="name">Inspection lines</field>
        <field name="res_model">qc.inspection.line</field>
        <field name="view_mode">tree,kanban</field>
        <field name="view_id" ref="qc_inspection_line_tree_view" />
    </record>
    <menuitem
        name="Inspection lines"
        parent="qc_inspection_menu_parent"
        id="qc_inspection_lines_menu"
        action="action_qc_inspection_line"
    />
</odoo>
