[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.
This commit is contained in:
Jérome Maes
2017-09-13 08:41:31 +02:00
parent d29242356a
commit d9cece2ef8
6 changed files with 46 additions and 15 deletions
+1 -1
View File
@@ -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):
@@ -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>
@@ -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,
})
@@ -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',
}
@@ -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"
@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_analytic_account_leaves_manager account.analytic.account analytic.model_account_analytic_account hr_holidays.group_hr_holidays_manager 1 0 0 0