<?xml version="1.0" encoding="UTF-8" ?>
<!--
    Copyright 2018-2019 Brainbean Apps (https://brainbeanapps.com)
    License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
    <record id="project_assignment_form" model="ir.ui.view">
        <field name="name">project.assignment.form</field>
        <field name="model">project.assignment</field>
        <field name="arch" type="xml">
            <form>
                <header />
                <sheet>
                    <div class="oe_button_box" name="button_box" />
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        attrs="{'invisible': [('active', '=', True)]}"
                    />
                    <field name="active" invisible="1" />
                    <group>
                        <field name="company_id" groups="base.group_multi_company" />
                        <field
                            name="project_id"
                            domain="[('active', '=', True)]"
                            invisible="context.get('default_project_id', False)"
                        />
                        <field name="role_id" options="{'no_create':True}" />
                        <field
                            name="user_id"
                            domain="[('active', '=', True)]"
                            options="{'no_create':True}"
                        />
                    </group>
                    <notebook />
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" />
                    <field name="message_ids" widget="mail_thread" />
                </div>
            </form>
        </field>
    </record>
    <record id="project_assignment_tree" model="ir.ui.view">
        <field name="name">project.assignment.tree</field>
        <field name="model">project.assignment</field>
        <field name="arch" type="xml">
            <tree editable="top">
                <field name="company_id" groups="base.group_multi_company" />
                <field
                    name="project_id"
                    domain="[('active', '=', True)]"
                    invisible="context.get('default_project_id', False)"
                />
                <field name="role_id" />
                <field name="user_id" domain="[('active', '=', True)]" />
            </tree>
        </field>
    </record>
    <record id="project_assignment_pivot" model="ir.ui.view">
        <field name="name">project.assignment.pivot</field>
        <field name="model">project.assignment</field>
        <field name="arch" type="xml">
            <pivot>
                <field name="company_id" groups="base.group_multi_company" />
                <field name="project_id" />
                <field name="user_id" type="row" />
                <field name="role_id" type="col" />
            </pivot>
        </field>
    </record>
    <record id="project_assignment_kanban" model="ir.ui.view">
        <field name="name">project.assignment.kanban</field>
        <field name="model">project.assignment</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile">
                <field name="company_id" groups="base.group_multi_company" />
                <field name="project_id" />
                <field name="user_id" />
                <field name="role_id" />
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_global_click">
                            <div class="row">
                                <div class="col-2">
                                    <img
                                        t-att-src="kanban_image('res.users', 'avatar_128', record.user_id.raw_value)"
                                        t-att-title="record.user_id.value"
                                        t-att-alt="record.user_id.value"
                                        width="40"
                                        height="40"
                                        class="oe_kanban_avatar float-left"
                                    />
                                </div>
                                <div class="col-10">
                                    <div>
                                        <strong>
                                            <t t-esc="record.user_id.value" />
                                        </strong>
                                    </div>
                                    <div class="text-muted">
                                        <span>
                                            <t t-esc="record.role_id.value" />
                                        </span>
                                    </div>
                                    <div
                                        class="text-muted"
                                        invisible="context.get('default_project_id', False)"
                                    >
                                        <span>
                                            <t t-esc="record.project_id.value" />
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>
    <record id="project_assignment_search" model="ir.ui.view">
        <field name="name">project.assignment.search</field>
        <field name="model">project.assignment</field>
        <field name="arch" type="xml">
            <search>
                <field name="active" />
                <field name="company_id" groups="base.group_multi_company" />
                <field name="project_id" />
                <field name="role_id" />
                <field name="user_id" />
                <filter
                    string="My Assignments"
                    name="my_assignments"
                    domain="[('user_id','=',uid)]"
                />
                <filter
                    string="Company-Wide"
                    name="companywide"
                    domain="[('project_id','=',False)]"
                />
                <separator />
                <filter
                    name="inactive"
                    string="Archived"
                    domain="[('active','=',False)]"
                />
                <group expand="0" string="Group By">
                    <filter
                        string="Project"
                        name="groupby_project"
                        context="{'group_by':'project_id'}"
                    />
                    <filter
                        string="Role"
                        name="groupby_role"
                        context="{'group_by':'role_id'}"
                    />
                    <filter
                        string="User"
                        name="groupby_user"
                        context="{'group_by':'user_id'}"
                    />
                    <filter
                        string="Company"
                        name="groupby_company"
                        context="{'group_by':'company_id'}"
                        groups="base.group_multi_company"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="project_assignment_view_all_action" model="ir.actions.act_window">
        <field name="name">Project Assignments</field>
        <field name="res_model">project.assignment</field>
        <field name="view_mode">tree,kanban,form,pivot,graph</field>
        <field name="search_view_id" ref="project_assignment_search" />
        <field name="context">{'search_default_groupby_project': 1}</field>
    </record>
    <record id="project_assignment_view_project_action" model="ir.actions.act_window">
        <field name="name">Assignments</field>
        <field name="res_model">project.assignment</field>
        <field name="view_mode">kanban,tree,form,pivot,graph</field>
        <field name="search_view_id" ref="project_assignment_search" />
        <field name="context">{'default_project_id': active_id}</field>
        <field name="domain">[('project_id','=',active_id)]</field>
    </record>
    <menuitem
        name="Assignments"
        id="menu_project_assignments"
        parent="project.menu_main_pm"
        action="project_assignment_view_all_action"
        sequence="2"
        groups="base.group_no_one,project.group_project_user"
    />
</odoo>
