<?xml version="1.0" ?>
<!-- Copyright 2019 Le Filament
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <data>

        <!-- Form View Project CG -->
        <record id="view_cgscop_project_timesheet_form" model="ir.ui.view">
            <field name="name">cgscop.project.timesheet.form</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <form string="Project">
                    <sheet string="Project">
                        <field name="active" invisible="1" />
                        <widget
                            name="web_ribbon"
                            title="Archivé"
                            bg_color="bg-danger"
                            attrs="{'invisible': [('active', '=', True)]}"
                        />
                        <div
                            class="oe_button_box"
                            name="button_box"
                            groups="base.group_user"
                        >
                            <button
                                class="oe_stat_button"
                                name="%(hr_timesheet.act_hr_timesheet_line_by_project)d"
                                type="action"
                                icon="fa-calendar"
                                string="Timesheets"
                                attrs="{'invisible': [('allow_timesheets', '=', False)]}"
                                groups="hr_timesheet.group_hr_timesheet_user"
                            />
                        </div>
                        <div class="oe_title">
                            <h1>
                                <field name="name" placeholder="Code activité UR" />
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field
                                    name="partner_id"
                                    string="Contact par défaut"
                                    domain="[('is_company', '=', True), ('ur_id', '=', ur_id)]"
                                    help="Contact par défaut auquel est rattaché cette activité. Ce contact sera sélectionné automatiquement dans les feuilles de temps"
                                    options="{'no_open': True, 'no_create': True}"
                                />
                                <field
                                    name="ur_id"
                                    string="Union Régionale"
                                    options="{'no_open': True, 'no_create': True}"
                                    required="1"
                                />
                                <field
                                    name="company_id"
                                    groups="base.group_multi_company"
                                    options="{'no_open': True, 'no_create': True}"
                                    string="Société"
                                    invisible="1"
                                />
                            </group>
                            <group>
                                <field
                                    name="cgscop_timesheet_code_id"
                                    required="1"
                                    placeholder="Code activité National"
                                    options="{'no_open': True, 'no_create': True}"
                                />
                                <field name="creation_invoiced" widget="boolean_toggle" />
                                <field name="analytic_account_id" invisible="1" />
                                <field name="privacy_visibility" invisible="1" />
                                <field name="allow_timesheets" invisible="1" />
                            </group>
                        </group>

                        <group
                            string="Configuration"
                            name="project_config"
                            groups="base.group_no_one"
                        >
                            <group>
                                <field
                                    name="user_id"
                                    string="Project Manager"
                                    attrs="{'readonly':[('active','=',False)]}"
                                    options="{'no_open': True, 'no_create': True}"
                                />
                                <field name="sequence" groups="base.group_no_one" />
                            </group>
                            <group>
                                <field name="allow_timesheets" />
                                <field name="privacy_visibility" widget="radio" />
                                <field
                                    name="resource_calendar_id"
                                    groups="base.group_no_one"
                                />
                            </group>
                        </group>

                    </sheet>
                    <div class="oe_chatter">
                        <field
                            name="message_follower_ids"
                            options="{'post_refresh':True}"
                            groups="base.group_user"
                        />
                        <field name="message_ids" />
                    </div>
                </form>
            </field>
        </record>

        <!-- Search View Project CG -->
        <record id="view_cgscop_project_timesheet_filter" model="ir.ui.view">
            <field name="name">cgscop.project.timesheet.search</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <search string="Search Project">
                    <field name="name" string="Code activité UR" />
                    <field
                        name="cgscop_timesheet_code_id"
                        string="Code activité National"
                    />
                    <field name="partner_id" string="Contact par défaut" />

                    <filter
                        string="Archived"
                        name="inactive"
                        domain="[('active','=',False)]"
                    />

                    <group expand="0" string="Group By">
                        <filter
                            string="Contact par défaut"
                            name="Partner"
                            context="{'group_by': 'partner_id'}"
                        />
                    </group>
                </search>
            </field>
        </record>

        <!-- Tree View Project CG -->
        <record id="view_cgscop_project_timesheet_tree" model="ir.ui.view">
            <field name="name">cgscop.project.timesheet.tree</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <tree decoration-muted="active == False" string="Projects">
                    <field name="sequence" widget="handle" />
                    <field name="active" invisible="1" />
                    <field name="name" />
                    <field
                        name="cgscop_timesheet_code_id"
                        options="{'no_open': True, 'no_create': True}"
                    />
                    <field
                        name="partner_id"
                        string="Contact"
                        options="{'no_open': True, 'no_create': True}"
                    />
                </tree>
            </field>
        </record>

        <!-- Kanban View Project CG -->
        <record id="view_cgscop_project_timesheet_kanban" model="ir.ui.view">
            <field name="name">cgscop.project.timesheet.kanban</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <kanban class="o_kanban_mobile">
                    <field name="user_id" string="Project Manager" />
                    <templates>
                        <t t-name="kanban-box">
                            <div
                                t-attf-class="oe_kanban_content oe_kanban_global_click o_kanban_get_form"
                            >
                                <div class="row">
                                    <div class="col-12">
                                        <strong><field
                                                name="name"
                                                string="Code activité UR"
                                            /></strong>
                                        <field
                                            name="cgscop_timesheet_code_id"
                                            string="Code activité CG"
                                        />
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-8">
                                        <field name="partner_id" string="Contact" />
                                    </div>
                                    <div class="col-4">
                                        <div class="oe_kanban_bottom_right">
                                            <img
                                                t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)"
                                                t-att-title="record.user_id.value"
                                                t-att-alt="record.user_id.value"
                                                width="24"
                                                height="24"
                                                class="oe_kanban_avatar float-right"
                                            />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="act_cgscop_project_timesheet" model="ir.actions.act_window">
            <field name="name">Codes activités UR</field>
            <field name="res_model">project.project</field>
            <field name="domain">[]</field>
            <field name="view_mode">tree,kanban,form</field>
            <field
                name="view_ids"
                eval="[(5, 0, 0),
                (0, 0, {'view_mode': 'tree', 'view_id': ref('view_cgscop_project_timesheet_tree')}),
                (0, 0, {'view_mode': 'kanban', 'view_id': ref('view_cgscop_project_timesheet_kanban')}),
                (0, 0, {'view_mode': 'form', 'view_id': ref('view_cgscop_project_timesheet_form')})]"
            />
            <field name="search_view_id" ref="view_cgscop_project_timesheet_filter" />
            <field name="context">{
                'default_privacy_visibility': 'employees',
                'default_allow_timesheets': True,
            }</field>
        </record>

        <menuitem
            name="Codes Activité UR"
            parent="hr_timesheet.hr_timesheet_menu_configuration"
            action="act_cgscop_project_timesheet"
            id="menu_action_project_lines_tree"
            sequence="35"
            groups="cgscop_partner.group_ur_list_modif,cgscop_partner.group_cg_administrator"
        />

    </data>
</odoo>