summaryrefslogtreecommitdiff
path: root/addons
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
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')
-rw-r--r--addons/hr_holidays/models/hr_holidays.py2
-rw-r--r--addons/hr_timesheet/views/res_config_settings_views.xml26
-rw-r--r--addons/project_timesheet_holidays/__init__.py16
-rw-r--r--addons/project_timesheet_holidays/__manifest__.py3
-rw-r--r--addons/project_timesheet_holidays/models/hr_holidays.py12
-rw-r--r--addons/project_timesheet_holidays/security/ir.model.access.csv2
6 files changed, 46 insertions, 15 deletions
diff --git a/addons/hr_holidays/models/hr_holidays.py b/addons/hr_holidays/models/hr_holidays.py
index 59d942c2ff6..66f95b60946 100644
--- a/addons/hr_holidays/models/hr_holidays.py
+++ b/addons/hr_holidays/models/hr_holidays.py
@@ -61,7 +61,7 @@ class HolidaysType(models.Model):
double_validation = fields.Boolean(string='Apply Double Validation',
help="When selected, the Allocation/Leave Requests for this type require a second validation to be approved.")
- company_id = fields.Many2one('res.company', string='Company')
+ company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id)
@api.multi
def get_days(self, employee_id):
diff --git a/addons/hr_timesheet/views/res_config_settings_views.xml b/addons/hr_timesheet/views/res_config_settings_views.xml
index ff3ecd6292b..0bd2760e6ec 100644
--- a/addons/hr_timesheet/views/res_config_settings_views.xml
+++ b/addons/hr_timesheet/views/res_config_settings_views.xml
@@ -59,19 +59,21 @@
</div>
</div>
</div>
- <h2>Leaves</h2>
- <div class="row mt16 o_settings_container" name="timesheet_control">
- <div class="col-xs-12 col-md-6 o_setting_box">
- <div class="o_setting_left_pane">
- <field name="module_project_timesheet_holidays"/>
- </div>
- <div class="o_setting_right_pane">
- <label for="module_project_timesheet_holidays"/>
- <div class="text-muted">
- Validated leaves create timesheets automatically.
+ <div name="section_leaves" groups="base.group_no_one">
+ <h2>Leaves</h2>
+ <div class="row mt16 o_settings_container" name="timesheet_control">
+ <div class="col-xs-12 col-md-6 o_setting_box">
+ <div class="o_setting_left_pane">
+ <field name="module_project_timesheet_holidays"/>
</div>
- <div class="content-group">
- <div id="module_project_timesheet_holidays"/>
+ <div class="o_setting_right_pane">
+ <label for="module_project_timesheet_holidays"/>
+ <div class="text-muted">
+ Validated leaves create timesheets automatically.
+ </div>
+ <div class="content-group">
+ <div id="module_project_timesheet_holidays"/>
+ </div>
</div>
</div>
</div>
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,
+ })
diff --git a/addons/project_timesheet_holidays/__manifest__.py b/addons/project_timesheet_holidays/__manifest__.py
index 39f549e5b0c..d98cef28b51 100644
--- a/addons/project_timesheet_holidays/__manifest__.py
+++ b/addons/project_timesheet_holidays/__manifest__.py
@@ -17,8 +17,11 @@ on leaves. Project and task can be configured company-wide.
'data': [
'views/res_config_settings_views.xml',
'views/hr_holidays_views.xml',
+ 'security/ir.model.access.csv',
+
],
'demo': [],
'installable': True,
'auto_install': True,
+ 'post_init_hook': 'post_init',
}
diff --git a/addons/project_timesheet_holidays/models/hr_holidays.py b/addons/project_timesheet_holidays/models/hr_holidays.py
index a2d2457f573..d71ece9631b 100644
--- a/addons/project_timesheet_holidays/models/hr_holidays.py
+++ b/addons/project_timesheet_holidays/models/hr_holidays.py
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import api, fields, models
+from odoo import api, fields, models, _
+from odoo.exceptions import ValidationError
class HolidaysType(models.Model):
_inherit = "hr.holidays.status"
- timesheet_generate = fields.Boolean('Generate Timesheet', help="If checked, when validating a leave, timesheet will be generated in the Vacation Project of the company.")
+ timesheet_generate = fields.Boolean('Generate Timesheet', default=True, help="If checked, when validating a leave, timesheet will be generated in the Vacation Project of the company.")
timesheet_project_id = fields.Many2one('project.project', string="Internal Project", help="The project will contain the timesheet generated when a leave is validated.")
timesheet_task_id = fields.Many2one('project.task', string="Internal Task for timesheet", domain="[('project_id', '=', timesheet_project_id)]")
@@ -21,6 +22,13 @@ class HolidaysType(models.Model):
self.timesheet_project_id = False
self.timesheet_task_id = False
+ @api.constrains('timesheet_generate')
+ def _check_timesheet_generate(self):
+ for holiday_status in self:
+ if holiday_status.timesheet_generate:
+ if not holiday_status.timesheet_project_id or not holiday_status.timesheet_task_id:
+ raise ValidationError(_('For the leaves to generate timesheet, the internal project and task are requried.'))
+
class Holidays(models.Model):
_inherit = "hr.holidays"
diff --git a/addons/project_timesheet_holidays/security/ir.model.access.csv b/addons/project_timesheet_holidays/security/ir.model.access.csv
new file mode 100644
index 00000000000..03c142ccb21
--- /dev/null
+++ b/addons/project_timesheet_holidays/security/ir.model.access.csv
@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_account_analytic_account_leaves_manager,account.analytic.account,analytic.model_account_analytic_account,hr_holidays.group_hr_holidays_manager,1,0,0,0