<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

    <record id="qc_problem_tree" model="ir.ui.view">
        <field name="name">qc.problem.tree</field>
        <field name="model">qc.problem</field>
        <field name="arch" type="xml">
            <tree string="Problem Tracking">
                <field name="name"/>
                <field name="problem_group_id"/>
                <field name="issue_count"/>
            </tree>
        </field>
    </record>

    <record id="qc_problem_form" model="ir.ui.view">
        <field name="name">qc.problem.form</field>
        <field name="model">qc.problem</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <field name="stage_id" widget="statusbar" clickable="True"
                           options="{'fold_field': 'fold'}"
                           domain="['|', ('qc_team_id', '=', qc_team_id), ('qc_team_id', '=', False)]"/>
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="name"/>
                            <field name="problem_group_id"/>
                            <field name="notes"/>
                        </group>
                        <group>
                            <field name="qc_team_id" widget="selection"/>
                            <field name="company_id"
                                   groups="base.group_multi_company"/>
                        </group>
                    </group>
                    <notebook>
                        <page name="qc_issues" string="QC Issues">
                            <field name="issue_ids"/>
                        </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="qc_problem_kanban_view" model="ir.ui.view">
        <field name="name">qc.problem.kanban</field>
        <field name="model">qc.problem</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_small_column" default_group_by="stage_id">
                <field name="stage_id"/>
                <field name="color"/>
                <field name="priority"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
                            <div class="oe_kanban_content">
                                <div class="o_kanban_record_top">
                                    <div class="o_kanban_record_headings">
                                        <strong class="o_kanban_record_title"><field name="name"/></strong><br/>
                                        <small class="o_kanban_record_subtitle text-muted">
                                            <field name="problem_group_id" invisible="context.get('default_problem_group_id', False)"/>
                                        </small>
                                    </div>
                                    <div class="o_dropdown_kanban dropdown" groups="base.group_user">
                                        <a role="button" class="dropdown-toggle o-no-caret btn" data-toggle="dropdown"
                                           href="#" aria-label="Dropdown menu" title="Dropdown menu">
                                            <span class="fa fa-ellipsis-v"/>
                                        </a>
                                        <div class="dropdown-menu" role="menu">
                                            <a t-if="widget.editable" role="menuitem" type="edit" class="dropdown-item">Edit</a>
                                            <a t-if="widget.deletable" role="menuitem" type="delete" class="dropdown-item">Delete</a>
                                            <div role="separator" class="dropdown-divider"/>
                                            <ul class="oe_kanban_colorpicker" data-field="color"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="o_kanban_record_body" name="info">
                                    <field name="issue_count"/> issues
                                </div>
                                <div class="o_kanban_record_bottom">
                                    <field name="priority" widget="priority" groups="base.group_user"/>
                                </div>
                            </div>
                            <div class="oe_clear"/>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <record model="ir.ui.view" id="qc_problem_search">
        <field name="name">qc.problem.search</field>
        <field name="model">qc.problem</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <field name="notes"/>
                <field name="qc_team_id"/>
                <field name="stage_id"/>
                <field name="problem_group_id"/>
                <separator/>
                <filter string="My Activities" name="activities_my"
                    domain="[('activity_ids.user_id', '=', uid)]"/>
                <separator/>
                <filter string="Late Activities" name="activities_overdue"
                    domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    help="Show all records which has next action date is before today"/>
                <filter string="Today Activities" name="activities_today"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"/>
                <filter string="Future Activities" name="activities_upcoming_all"
                    domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))
                    ]"/>
                <group expand="0" string="Group By...">
                    <filter name="groupby_stage" string="Stage" domain="[]" context="{'group_by':'stage_id'}"/>
                    <filter name="groupby_problem_group" string="Problem Group" domain="[]" context="{'group_by': 'problem_group_id'}"/>
                    <filter name="groupby_qc_team" string="QC Team" domain="[]" context="{'group_by': 'qc_team_id'}"/>
                    <filter name="groupby_company" string="Company" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
                </group>
            </search>
        </field>
    </record>


    <record id="qc_problem_action" model="ir.actions.act_window">
        <field name="name">Problem Tracking</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">qc.problem</field>
        <field name="view_type">form</field>
        <field name="view_mode">kanban,tree,form</field>
    </record>

    <menuitem id="menu_qc_problem_tracking"
          parent="quality_control.qc_menu"
          sequence="60" name="Problem Tracking"/>

    <menuitem id="menu_qc_problem"
          parent="quality_control_issue.menu_qc_problem_tracking"
          action="qc_problem_action"
          sequence="20" name="Problems"/>

</odoo>
