<?xml version="1.0" encoding="utf-8" ?>
<odoo>

        <record id="view_mgmtsystem_action_tree" model="ir.ui.view">
            <field name="name">mgmtsystem.action.tree</field>
            <field name="model">mgmtsystem.action</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree>
                    <field name="reference" />
                    <field name="name" />
                    <field name="type_action" />
                    <field name="user_id" />
                    <field name="date_deadline" />
                    <field name="stage_id" />
                    <field name="company_id" groups="base.group_multi_company" />
                </tree>
            </field>
        </record>

        <record id="view_mgmtsystem_action_filter" model="ir.ui.view">
            <field name="name">mgmtsystem.action.filter</field>
            <field name="model">mgmtsystem.action</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
            <!-- TODO: validation broken somehow -->
                <search string="Action">
                    <field name="name" />
                    <field name="reference" />
                    <field name="tag_ids" />
                    <field name="create_date" />
                    <field name="user_id" />
                    <field name="system_id" />
                    <field name="company_id" groups="base.group_multi_company" />
                    <newline />
                    <filter
                    name="pending"
                    string="Pending"
                    domain="[('stage_id.is_ending', '=', False)]"
                />
                    <separator />
                    <filter
                    name="my_actions"
                    string="My Actions"
                    domain="[('user_id','=',uid)]"
                />
                    <filter
                    name="my_followed_actions"
                    string="My Followed Actions"
                    domain="[('message_is_follower', '=', True)]"
                />
                    <separator />
                    <filter
                    name="message_needaction"
                    string="Unread Messages"
                    domain="[('message_needaction','=',True)]"
                />
                    <filter
                    name="inactive"
                    string="Archived"
                    domain="[('active','=',False)]"
                />
                    <separator />
                    <filter
                    name="activities_my"
                    string="My Activities"
                    domain="[('activity_ids.user_id', '=', uid)]"
                />
                    <separator />
                    <filter
                    name="activities_overdue"
                    string="Late Activities"
                    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
                    name="activities_today"
                    string="Today Activities"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"
                />
                    <filter
                    name="activities_upcoming_all"
                    string="Future Activities"
                    domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]"
                />
                    <group expand="0" string="Group By">
                        <filter
                        name="group_by_user"
                        string="User"
                        context="{'group_by':'user_id'}"
                    />
                        <filter
                        name="group_by_type"
                        string="Type"
                        context="{'group_by':'type_action'}"
                    />
                        <filter
                        name="group_by_state"
                        string="Stage"
                        context="{'group_by':'stage_id'}"
                    />
                        <filter
                        name="group_by_company"
                        string="Company"
                        context="{'group_by':'company_id'}"
                        groups="base.group_multi_company"
                    />
                    </group>
                </search>
            </field>
        </record>

        <record id="view_mgmtsystem_action_form" model="ir.ui.view">
            <field name="name">mgmtsystem.action.form</field>
            <field name="model">mgmtsystem.action</field>
            <field name="arch" type="xml">
                <form string="Action">
                    <header>
                        <field
                        name="stage_id"
                        widget="statusbar"
                        options="{'clickable': 1}"
                    />
                    </header>
                    <sheet string="Action">
                        <div class="oe_title" modifiers="{}">
                            <h1 class="o_row" modifiers="{}">
                                <field name="priority" widget="priority" />
                                <field
                                name="name"
                                placeholder="Action title..."
                                required="1"
                            />
                            </h1>
                        </div>
                        <group name="main">
                            <group name="config">
                                <field name="type_action" />
                                <field name="user_id" />
                                <field name="date_deadline" />
                            </group>
                            <group name="meta">
                                <field name="reference" />
                                <field
                                name="tag_ids"
                                widget="many2many_tags"
                                options="{'color_field': 'color', 'no_create_edit': True}"
                            />
                            </group>
                        </group>
                        <notebook>
                            <page name="desc" string="Description">
                                <field name="description" nolabel="1" />
                            </page>
                            <page name="extra" string="Extra Information">
                                <group name="main_extra">
                                    <group name="extra">
                                        <field name="sequence" />
                                        <field name="system_id" />
                                        <field
                                        name="company_id"
                                        groups="base.group_multi_company"
                                    />
                                    </group>
                                    <group name="dates">
                                        <field name="create_date" />
                                        <field
                                        name="date_open"
                                        attrs="{'invisible': [('date_open', '=', False)]}"
                                    />
                                        <field
                                        name="date_closed"
                                        attrs="{'invisible': [('date_closed', '=', False)]}"
                                    />
                                    </group>
                                </group>
                            </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field
                        name="message_follower_ids"
                        widget="mail_followers"
                        groups="base.group_user"
                    />
                        <field name="activity_ids" widget="mail_activity" />
                        <field name="message_ids" widget="mail_thread" />
                    </div>
                </form>
            </field>
        </record>

        <record id="view_mgmtsystem_action_kanban" model="ir.ui.view">
            <field name="name">mgmtsystem.action.kanban</field>
            <field name="model">mgmtsystem.action</field>
            <field name="arch" type="xml">
                <kanban default_group_by="stage_id" class="o_kanban_small_column">
                    <field name="name" />
                    <field name="priority" />
                    <field name="tag_ids" />
                    <field name="sequence" />
                    <field name="type_action" />
                    <field name="reference" />
                    <field name="user_id" />
                    <field name="create_date" />
                    <field name="date_deadline" />
                    <field name="activity_ids" />
                    <field name="activity_state" />
                    <field name="message_needaction_counter" />
                    <templates>
                        <field name="date_deadline" />
                        <t t-name="kanban-box">
                            <t t-set="type_action_color">#ffffff</t>
                            <t
                            t-if="record.type_action.raw_value and record.type_action.raw_value == 'immediate'"
                            t-set="type_action_color"
                        >oe_kanban_text_red</t>
                            <t
                            t-if="record.type_action.raw_value and record.type_action.raw_value == 'correction'"
                            t-set="type_action_color"
                        >#ffa500</t>
                            <t
                            t-if="record.type_action.raw_value and record.type_action.raw_value == 'prevention'"
                            t-set="type_action_color"
                        >#00ff00</t>
                            <t
                            t-if="record.type_action.raw_value and record.type_action.raw_value == 'improvement'"
                            t-set="type_action_color"
                        >#0000ff</t>
                            <div
                            t-attf-class="#{kanban_color(type_action_color)} 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="system_id"
                                                invisible="context.get('default_system_id', False)"
                                            />
                                                <t
                                                t-if="record.date_deadline.raw_value and record.date_deadline.raw_value lt (new Date())"
                                                t-set="red"
                                            >oe_kanban_text_red</t>
                                                <span t-attf-class="#{red || ''}"><i
                                                ><field
                                                        name="date_deadline"
                                                    /></i></span>
                                            </small>
                                        </div>

                                        <div
                                        class="o_dropdown_kanban dropdown"
                                        groups="base.group_user"
                                    >
                                            <a
                                            class="dropdown-toggle o-no-caret btn"
                                            role="button"
                                            data-toggle="dropdown"
                                            data-display="static"
                                            href="#"
                                            aria-label="Dropdown menu"
                                            title="Dropdown menu"
                                        >
                                                <span class="fa fa-ellipsis-v" />
                                            </a>
                                            <div class="dropdown-menu" role="menu">
                                                <t t-if="widget.editable"><a
                                                    role="menuitem"
                                                    type="edit"
                                                    class="dropdown-item"
                                                >Edit Task</a></t>
                                                <t t-if="widget.deletable"><a
                                                    role="menuitem"
                                                    type="delete"
                                                    class="dropdown-item"
                                                >Delete</a></t>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="o_kanban_record_body">
                                        <field
                                        name="tag_ids"
                                        widget="many2many_tags"
                                        options="{'color_field': 'color'}"
                                    />
                                    </div>

                                    <div class="o_kanban_record_bottom">
                                        <div class="oe_kanban_bottom_left">
                                            <field name="priority" widget="priority" />
                                            <field
                                            name="activity_ids"
                                            widget="kanban_activity"
                                        />
                                            <t
                                            t-if="record.message_needaction_counter.raw_value"
                                        >
                                                <span
                                                class='oe_kanban_mail_new'
                                                title='Unread Messages'
                                            ><i class='fa fa-comments' /><t
                                                    t-raw="record.message_needaction_counter.raw_value"
                                                /></span>
                                            </t>
                                        </div>
                                        <div class="oe_kanban_bottom_right">
                                            <field
                                            name="user_id"
                                            widget="many2one_avatar_user"
                                        />
                                        </div>
                                    </div>
                                </div>
                                <div class="oe_clear" />

                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="open_mgmtsystem_action_list" model="ir.actions.act_window">
            <field name="name">Actions</field>
            <field name="res_model">mgmtsystem.action</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="context">{"search_default_my_actions": 1}</field>
        </record>

</odoo>
