Debian Codegraph @

addons/hr_timesheet/__init__.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from . import controllers
5 from . import models
6 from . import report
7 from . import wizard
8
9 from odoo import fields
10
11 from odoo.addons.project import _check_exists_collaborators_for_project_sharing
12 from odoo.tools.sql import SQL
13
14
15 def create_internal_project(env):
16 # allow_timesheets is set by default, but erased for existing projects at
17 # installation, as there is no analytic account for them.
18 env['project.project'].search([]).write({'allow_timesheets': True})
19
20 admin = env.ref('base.user_admin', raise_if_not_found=False)
21 if not admin:
22 return
23 project_ids = env['res.company'].search([])._create_internal_project_task()
24 env['account.analytic.line'].create([{
25 'name': env._("Analysis"),
26 'user_id': admin.id,
27 'date': fields.Date.today(),
28 'unit_amount': 0,
29 'project_id': task.project_id.id,
30 'task_id': task.id,
31 } for task in project_ids.task_ids.filtered(lambda t: t.company_id in admin.employee_ids.company_id)])
32
33 _check_exists_collaborators_for_project_sharing(env)
34
35 def _uninstall_hook(env):
36
37 def update_action_window(xmlid):
38 act_window = env.ref(xmlid, raise_if_not_found=False)
39 if act_window and act_window.domain and 'is_internal_project' in act_window.domain:
40 act_window.domain = [("is_template", "=", False)]
41
42 update_action_window('project.open_view_project_all')
43 update_action_window('project.open_view_project_all_group_stage')
44
45 # archive the internal projects
46 project_ids = env['res.company'].search([('internal_project_id', '!=', False)]).mapped('internal_project_id')
47 if project_ids:
48 project_ids.write({'active': False})
49
50 env['ir.model.data'].search([('name', 'ilike', 'internal_project_default_stage')]).unlink()
51
52
53 def _pre_init_hook(env):
54 """
55 Create manually new compute+stored columns to allow installing the module on large databases without trigger an Out-of-memory error.
56 """
57 env.cr.execute(SQL("""
58 ALTER TABLE account_analytic_line
59 -- The task_id is set to False when there is no project_id on the line, but at installation,
60 -- no line is associated with a project -> task_id = False
61 ADD COLUMN IF NOT EXISTS task_id INT4,
62 -- At fresh installation, `task_id` is False -> parent_task_id, which is related to it, will also be False
63 ADD COLUMN IF NOT EXISTS parent_task_id INT4,
64 -- The project_id is defined as being the same as the one from the task, but task_id = False -> project_id = False
65 ADD COLUMN IF NOT EXISTS project_id INT4,
66 -- The department_id is the one from the `employee_id`, but `employee_id` by default is False -> department_id = False
67 ADD COLUMN IF NOT EXISTS department_id INT4,
68 -- The manager_id is the manager of the employee_id, but there is no `employee_id` by default -> manager_id = False
69 ADD COLUMN IF NOT EXISTS manager_id INT4
70 """))