<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2012 - Now Savoir-faire Linux <https://www.savoirfairelinux.com/>
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
    <!-- KPI -->
    <record id="view_kpi_tree" model="ir.ui.view">
        <field name="name">kpi.tree</field>
        <field name="model">kpi</field>
        <field eval="8" name="priority"/>
        <field name="arch" type="xml">
            <tree string="Key Performance Indicators">
                <field name="name"/>
                <field name="value" widget="progressbar"/>
                <field name="category_id"/>
                <field name="kpi_type"/>
                <field name="company_id" groups="base.group_multi_company"/>
            </tree>
        </field>
    </record>
    <record id="view_kpi_kanban" model="ir.ui.view">
        <field name="name">kpi.kanban</field>
        <field name="model">kpi</field>
        <field name="arch" type="xml">
            <kanban class="o_kpi_kanban" create="false" edit="false" delete="false">
                <field name="id"/>
                <field name="display_name"/>
                <field name="color"/>
                <field name="value"/>
                <field name="last_execution"/>
                <templates>
                    <t t-name="kanban-box">
                        <div class="oe_kanban_global_click o_kpi_kanban">
                            <div class="oe_kanban_details">
                                <div class="o_kanban_record_title oe_partner_heading"><strong><field name="display_name"/></strong></div>
                                <div class="o_kanban_tags_section oe_kanban_partner_categories"  t-attf-style="color:#{record.color.raw_value}">
                                    <strong><field name="value"/></strong>
                                </div><div class="o_kanban_tags_section oe_kanban_partner_categories">
                                    <field name="last_execution"/>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <record id="view_kpi_filter" model="ir.ui.view">
        <field name="name">kpi.filter</field>
        <field name="model">kpi</field>
        <field name="arch" type="xml">
            <search string="KPI">
                <group>
                    <filter name="active"
                            icon="terp-document-new"
                            domain="[('active','=',True)]"
                            string="Active"
                            help="Only active KPIs are computed by the scheduler based on the periodicity configuration."/>
                    <separator orientation="vertical"/>
                    <field name="name"/>
                    <field name="category_id"/>
                    <field name="company_id" group="base.group_multi_company"/>
                </group>
                <newline/>
                <group expand="0" name="Group By...">
                    <filter name="Category" context="{'group_by':'category_id'}"/>
                    <filter name="Type" context="{'group_by':'kpi_type'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="view_kpi_form" model="ir.ui.view">
        <field name="name">kpi.form</field>
        <field name="model">kpi</field>
        <field name="arch" type="xml">
            <form string="Key Performance Indicator">
                <sheet>
                    <group>
                        <group>
                            <field name="name" />
                            <field name="threshold_id"/>
                            <field name="category_id"/>
                        </group>
                        <group>
                            <field name="value" colspan="2"/>
                            <field name="active" colspan="2"/>
                            <field name="company_id"
                                   groups="base.group_multi_company"/>
                            <button name="compute_kpi_value"
                                    string="Compute KPI Now"
                                    colspan="2"
                                    type="object"
                                    groups="kpi.group_kpi_manager"/>
                        </group>
                    </group>
                    <notebook colspan="6">
                        <page string="History">
                            <field name="history_ids" readonly="1" nolabel="1"/>
                        </page>
                        <page string="Computation" groups="kpi.group_kpi_manager">
                            <group col="6">
                                <field name="periodicity" colspan="3"/>
                                <field name="periodicity_uom" colspan="3"/>
                                <field name="next_execution_date" colspan="3"/>
                                <separator string="KPI Computation" colspan="6"/>
                                <newline/>
                                <field name="kpi_type" colspan="2"/>
                                <field name="dbsource_id" colspan="2"
                                       attrs="{'invisible' : [('kpi_type', '!=', 'external')]}"/>
                                <newline/>
                                <field name="kpi_code" colspan="6"/>
                            </group>
                        </page>
                        <page string="Description">
                            <field name="description" nolabel="1"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="open_kpi_dashboard">
        <field name="name">KPI Dashboard</field>
        <field name="res_model">kpi</field>
        <field name="view_type">form</field>
        <field name="view_mode">kanban,form</field>
        <field name="search_view_id" ref="view_kpi_filter"/>
    </record>

    <record id="action_view_kpi_kanban" model="ir.actions.act_window.view">
        <field eval="1" name="sequence"/>
        <field name="view_mode">kanban</field>
        <field name="view_id" ref="view_kpi_kanban"/>
        <field name="act_window_id" ref="open_kpi_dashboard"/>
    </record>

    <record model="ir.actions.act_window" id="open_kpi_list">
        <field name="name">KPI Maintenance</field>
        <field name="res_model">kpi</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_kpi_filter"/>
    </record>

    <record id="action_view_kpi_tree" model="ir.actions.act_window.view">
        <field eval="2" name="sequence"/>
        <field name="view_mode">tree</field>
        <field name="view_id" ref="view_kpi_tree"/>
        <field name="act_window_id" ref="open_kpi_list"/>
    </record>

</odoo>
