summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRémy Baranx (bar) <bar@odoo.com>2020-02-12 10:46:56 +0000
committerYannick Tivisse <yti@odoo.com>2020-06-23 08:57:08 +0000
commitcd4e854e417cec1ae489a068f7bd362edaed789f (patch)
treee4f8d2cdb50f70c75c0195bf540069af5018488d /addons
parentd924d89ab81d347937db48e4fb03cce408fb2cab (diff)
[IMP] project_timesheet_holidays : convert onchange to stored-editable computed fields.
The 'timesheet_generate' and 'timesheet_task_id' fields have been set as stored-editable computed fields. The condition to compute the timesheet_generat field has changed to be coherent with the _check_timesheet_generate constraint. Keep the timesheet_generate field without its default value (True) to avoid raising a ValidationError through the _check_timesheet_generate constraint before the timesheet_generate field has been computed.
Diffstat (limited to 'addons')
-rw-r--r--addons/project_timesheet_holidays/models/hr_holidays.py46
-rw-r--r--addons/project_timesheet_holidays/models/res_config_settings.py12
2 files changed, 35 insertions, 23 deletions
diff --git a/addons/project_timesheet_holidays/models/hr_holidays.py b/addons/project_timesheet_holidays/models/hr_holidays.py
index 0c2322496f8..4abb2e866b5 100644
--- a/addons/project_timesheet_holidays/models/hr_holidays.py
+++ b/addons/project_timesheet_holidays/models/hr_holidays.py
@@ -16,29 +16,31 @@ class HolidaysType(models.Model):
company = self.company_id if self.company_id else self.env.company
return company.leave_timesheet_task_id.id
- timesheet_generate = fields.Boolean('Generate Timesheet', default=True, help="If checked, when validating a time off, timesheet will be generated in the Vacation Project of the company.")
+ timesheet_generate = fields.Boolean(
+ 'Generate Timesheet', compute='_compute_timesheet_generate', store=True, readonly=False,
+ help="If checked, when validating a time off, timesheet will be generated in the Vacation Project of the company.")
timesheet_project_id = fields.Many2one('project.project', string="Project", default=_default_project_id, domain="[('company_id', '=', company_id)]", help="The project will contain the timesheet generated when a time off is validated.")
- timesheet_task_id = fields.Many2one('project.task', string="Task for timesheet", default=_default_task_id, domain="[('project_id', '=', timesheet_project_id), ('company_id', '=', company_id)]")
-
- @api.onchange('timesheet_task_id')
- def _onchange_timesheet_generate(self):
- if self.timesheet_task_id or self.timesheet_project_id:
- self.timesheet_generate = True
- else:
- self.timesheet_generate = False
-
- @api.onchange('timesheet_project_id')
- def _onchange_timesheet_project(self):
- company = self.company_id if self.company_id else self.env.company
- default_task_id = company.leave_timesheet_task_id
- if default_task_id and default_task_id.project_id == self.timesheet_project_id:
- self.timesheet_task_id = default_task_id
- else:
- self.timesheet_task_id = False
- if self.timesheet_project_id:
- self.timesheet_generate = True
- else:
- self.timesheet_generate = False
+ timesheet_task_id = fields.Many2one(
+ 'project.task', string="Task for timesheet", compute='_compute_timesheet_task_id',
+ store=True, readonly=False, default=_default_task_id,
+ domain="[('project_id', '=', timesheet_project_id),"
+ "('company_id', '=', company_id)]")
+
+ @api.depends('timesheet_task_id', 'timesheet_project_id')
+ def _compute_timesheet_generate(self):
+ for leave_type in self:
+ leave_type.timesheet_generate = leave_type.timesheet_task_id and leave_type.timesheet_project_id
+
+ @api.depends('timesheet_project_id')
+ def _compute_timesheet_task_id(self):
+ for leave_type in self:
+ company = leave_type.company_id if leave_type.company_id else self.env.company
+ default_task_id = company.leave_timesheet_task_id
+
+ if default_task_id and default_task_id.project_id == leave_type.timesheet_project_id:
+ leave_type.timesheet_task_id = default_task_id
+ else:
+ leave_type.timesheet_task_id = False
@api.constrains('timesheet_generate', 'timesheet_project_id', 'timesheet_task_id')
def _check_timesheet_generate(self):
diff --git a/addons/project_timesheet_holidays/models/res_config_settings.py b/addons/project_timesheet_holidays/models/res_config_settings.py
index 2bf86555488..dd3ea5ee848 100644
--- a/addons/project_timesheet_holidays/models/res_config_settings.py
+++ b/addons/project_timesheet_holidays/models/res_config_settings.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import fields, models
+from odoo import fields, models,api
class ResConfigSettings(models.TransientModel):
@@ -9,3 +9,13 @@ class ResConfigSettings(models.TransientModel):
leave_timesheet_project_id = fields.Many2one(related='company_id.leave_timesheet_project_id', string="Internal Project", domain="[('company_id', '=', company_id)]", readonly=False)
leave_timesheet_task_id = fields.Many2one(related='company_id.leave_timesheet_task_id', string="Time Off Task", domain="[('company_id', '=', company_id)]", readonly=False)
+
+ @api.onchange('leave_timesheet_project_id')
+ def _onchange_timesheet_project_id(self):
+ if self.leave_timesheet_project_id != self.leave_timesheet_task_id.project_id:
+ self.leave_timesheet_task_id = False
+
+ @api.onchange('leave_timesheet_task_id')
+ def _onchange_timesheet_task_id(self):
+ if self.leave_timesheet_task_id:
+ self.leave_timesheet_project_id = self.leave_timesheet_task_id.project_id