<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data noupdate="1">
        <record model="res.groups.privilege" id="res_groups_privilege_timesheets">
            <field name="name">Timesheets</field>
            <field name="sequence">13</field>
            <field name="category_id" ref="base.module_category_services"/>
        </record>

        <record id="group_hr_timesheet_user" model="res.groups">
            <field name="name">User: own timesheets only</field>
            <field name="sequence">10</field>
            <field name="privilege_id" ref="res_groups_privilege_timesheets"/>
            <field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
            <field name="user_ids" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
        </record>

        <record id="group_hr_timesheet_approver" model="res.groups">
            <field name="name">User: all timesheets</field>
            <field name="sequence">20</field>
            <field name="privilege_id" ref="res_groups_privilege_timesheets"/>
            <field name="implied_ids" eval="[(4, ref('hr_timesheet.group_hr_timesheet_user'))]"/>
        </record>

        <record id="group_timesheet_manager" model="res.groups">
            <field name="name">Administrator</field>
            <field name="sequence">30</field>
            <field name="privilege_id" ref="res_groups_privilege_timesheets"/>
            <field name="implied_ids" eval="[(4, ref('hr_timesheet.group_hr_timesheet_approver')), (4, ref('hr.group_hr_user'))]"/>
            <field name="user_ids" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
        </record>

        <record id="timesheet_line_rule_portal_user" model="ir.rule">
            <field name="name">account.analytic.line.timesheet.portal.user</field>
            <field name="model_id" ref="analytic.model_account_analytic_line"/>
            <field name="active">0</field>
            <field name="domain_force">[
                ('project_id', '!=', False),
                ('message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]),
                ('project_id.privacy_visibility', 'in', ['invited_users', 'portal']),
                ('project_id.collaborator_ids.partner_id', 'in', [user.partner_id.id]),
            ]</field>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="True"/>
            <field name="perm_unlink" eval="True"/>
            <field name="groups" eval="[(4, ref('base.group_portal'))]"/>
        </record>

        <record id="timesheet_line_rule_user" model="ir.rule">
            <field name="name">account.analytic.line.timesheet.user</field>
            <field name="model_id" ref="analytic.model_account_analytic_line"/>
            <field name="domain_force">[
                ('user_id', '=', user.id),
                ('project_id', '!=', False),
                '|', '|',
                    ('project_id.privacy_visibility', 'in', ['employees', 'portal']),
                    ('partner_id', '=', user.partner_id.id),
                    ('message_partner_ids', 'in', [user.partner_id.id])
            ]</field>
            <field name="groups" eval="[(4, ref('group_hr_timesheet_user'))]"/>
        </record>

        <record id="timesheet_line_rule_approver" model="ir.rule">
            <field name="name">account.analytic.line.timesheet.approver</field>
            <field name="model_id" ref="analytic.model_account_analytic_line" />
            <field name="domain_force">[
                ('project_id', '!=', False),
                '|', '|',
                    ('project_id.privacy_visibility', 'in', ['employees', 'portal']),
                    ('message_partner_ids', 'in', [user.partner_id.id]),
                    ('partner_id', '=', user.partner_id.id),
            ]</field>
            <field name="groups" eval="[(4, ref('hr_timesheet.group_hr_timesheet_approver'))]" />
        </record>

        <record id="timesheet_line_rule_manager" model="ir.rule">
            <field name="name">account.analytic.line.timesheet.manager</field>
            <field name="model_id" ref="analytic.model_account_analytic_line"/>
            <field name="domain_force">[('project_id', '!=', False)]</field>
            <field name="groups" eval="[(4, ref('group_timesheet_manager')), (4, ref('project.group_project_manager'))]"/>
        </record>

        <record id="project.group_project_manager" model="res.groups">
            <field name="implied_ids" eval="[(4, ref('hr_timesheet.group_hr_timesheet_approver'))]"/>
        </record>

        <record model="ir.rule" id="timesheets_analysis_report_comp_rule">
            <field name="name">Timesheets Analysis Report multi-company</field>
            <field name="model_id" ref="model_timesheets_analysis_report"/>
            <field name="domain_force">[('company_id', 'in', company_ids)]</field>
        </record>

        <record id="timesheet_analysis_report_department_manager" model="ir.rule">
            <field name="name">Timesheets Analysis Report user</field>
            <field name="model_id" ref="model_timesheets_analysis_report"/>
            <field name="domain_force">[
                ('has_department_manager_access', '=', True),
            ]</field>
            <field name="groups" eval="[(4, ref('base.group_user'))]"/>
        </record>

        <record id="timesheet_analysis_report_user" model="ir.rule">
            <field name="name">Timesheets Analysis Report user</field>
            <field name="model_id" ref="model_timesheets_analysis_report"/>
            <field name="domain_force">[
                ('user_id', '=', user.id),
                '|',
                    ('project_id.privacy_visibility', 'in', ['employees', 'portal']),
                    ('message_partner_ids', 'in', [user.partner_id.id])
            ]</field>
            <field name="groups" eval="[(4, ref('group_hr_timesheet_user'))]"/>
        </record>

        <record id="timesheet_analysis_report_approver" model="ir.rule">
            <field name="name">Timesheets Analysis Report approver</field>
            <field name="model_id" ref="model_timesheets_analysis_report"/>
            <field name="domain_force">[
                '|',
                    ('project_id.privacy_visibility', 'in', ['employees', 'portal']),
                    ('project_id.message_partner_ids', 'in', [user.partner_id.id])
            ]</field>
            <field name="groups" eval="[(4, ref('group_hr_timesheet_approver'))]"/>
        </record>

        <record id="timesheet_analysis_report_manager" model="ir.rule">
            <field name="name">Timesheets Analysis Report manager</field>
            <field name="model_id" ref="model_timesheets_analysis_report"/>
            <field name="domain_force">[(1, '=', 1)]</field>
            <field name="groups" eval="[(4, ref('group_timesheet_manager')), (4, ref('project.group_project_manager'))]"/>
        </record>
    </data>
</odoo>
