summaryrefslogtreecommitdiff
path: root/addons/project_timesheet_holidays/__init__.py
diff options
context:
space:
mode:
authorJérome Maes <jem@openerp.com>2017-08-07 15:49:53 +0200
committerJérome Maes <jem@openerp.com>2017-09-13 08:41:31 +0200
commitd9cece2ef82f2848fa642d482e94c3baeba0691d (patch)
tree7505788c79ccc599cca6c928ba827252dc8eb171 /addons/project_timesheet_holidays/__init__.py
parentd29242356a65ae2838f5ec676d05d902a7753e34 (diff)
[IMP] project_timesheet_holidays: ease leave type configuration
A leave type now generate timesheet by default. So the internal project/task are taken from the leave type company (a default value for the company has been added). To allow the hr leave manager to select a project, he should be alble to read the analytic account (otherwise, crash when calling name_get). Setting the default internal project/task is advanced, so hidden in debug mode on timesheet config.
Diffstat (limited to 'addons/project_timesheet_holidays/__init__.py')
-rw-r--r--addons/project_timesheet_holidays/__init__.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/addons/project_timesheet_holidays/__init__.py b/addons/project_timesheet_holidays/__init__.py
index dc5e6b693d1..cb09489a1e7 100644
--- a/addons/project_timesheet_holidays/__init__.py
+++ b/addons/project_timesheet_holidays/__init__.py
@@ -2,3 +2,19 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+
+
+def post_init(cr, registry):
+ """ Set the timesheet project and task on existing leave type. Do it in post_init to
+ be sure the internal project/task of res.company are set. (Since timesheet_generate field
+ is true by default, those 2 fields are required on the leave type).
+ """
+ from odoo import api, SUPERUSER_ID
+
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ for leave_type in env['hr.holidays.status'].search([('timesheet_generate', '=', True), ('timesheet_project_id', '=', False)]):
+ company = leave_type.company_id or env.user.company_id
+ leave_type.write({
+ 'timesheet_project_id': company.leave_timesheet_project_id.id,
+ 'timesheet_task_id': company.leave_timesheet_task_id.id,
+ })