Files
odoo_source/addons/hr_timesheet/__init__.py
T
Dominik RuboandKevin Baptiste a93f1e8d9b [IMP] project: enable config-selected features in projects
This change ensures that when the user activates optional features of the
project app, they are enabled in existing projects as well as newly created
projects automatically, which is likely what the user expects.

For most optional features, this behavior was already in place. It was not in
place yet for the sub-tasks and timesheets features, which this change fixes.

Two added tests check the behavior described above for features that are
activated through a `group_*` field on `res.config.settings` (sub-tasks,
recurring tasks and ratings). The tests do not cover features that are
activated through a `module_*` field, as such fields require the installation
of further modules and we cannot simulate this.

Task 2297054

closes odoo/odoo#60106

X-original-commit: 8dd0edae898a532dbe7e4f18c9118b9b68e57900
Related: odoo/enterprise#14119
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Co-authored-by: Kevin Baptiste <50135801+kba-odoo@users.noreply.github.com>
2020-10-15 14:18:30 +00:00

44 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
from . import report
from . import wizard
from odoo import api, fields, SUPERUSER_ID, _
def create_internal_project(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
# allow_timesheets is set by default, but erased for existing projects at
# installation, as there is no analytic account for them.
env['project.project'].search([]).write({'allow_timesheets': True})
admin = env.ref('base.user_admin', raise_if_not_found=False)
if not admin:
return
project_vals = []
for company in env['res.company'].search([]):
company = company.with_company(company)
project_vals += [{
'name': _('Internal'),
'allow_timesheets': True,
'company_id': company.id,
'task_ids': [(0, 0, {
'name': name,
'company_id': company.id,
}) for name in [_('Training'), _('Meeting')]]
}]
project_ids = env['project.project'].create(project_vals)
env['account.analytic.line'].create([{
'name': _("Analysis"),
'user_id': admin.id,
'date': fields.datetime.today(),
'unit_amount': 0,
'project_id': task.project_id.id,
'task_id': task.id,
} for task in project_ids.task_ids.filtered(lambda t: t.company_id in admin.employee_ids.company_id)])