[FIX] project_timesheet_holidays: multi company fixes
In a multi company environment, some adjustment must be done: - the company of an internal project of a company should be in that company - the generate timesheet on holidays validation must be in the company the task (or internal project) The company should be correctly propagate to timesheets. Task-1999686
This commit is contained in:
@@ -83,6 +83,7 @@ class Holidays(models.Model):
|
||||
'date': fields.Date.to_string(day_date),
|
||||
'holiday_id': holiday.id,
|
||||
'employee_id': holiday.employee_id.id,
|
||||
'company_id': holiday_task.company_id.id or holiday_project.company_id.id,
|
||||
})
|
||||
|
||||
return super(Holidays, self)._validate_leave_request()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
@@ -14,6 +15,13 @@ class Company(models.Model):
|
||||
'project.task', string="Time Off Task",
|
||||
domain="[('project_id', '=', leave_timesheet_project_id)]")
|
||||
|
||||
@api.constrains('leave_timesheet_project_id')
|
||||
def _check_leave_timesheet_project_id_company(self):
|
||||
for company in self:
|
||||
if company.leave_timesheet_project_id:
|
||||
if company.leave_timesheet_project_id.company_id != company:
|
||||
raise ValidationError(_('The Internal Project of a company should be in that company.'))
|
||||
|
||||
def init(self):
|
||||
self.search([('leave_timesheet_project_id', '=', False)])._create_leave_project_task()
|
||||
|
||||
@@ -40,7 +48,7 @@ class Company(models.Model):
|
||||
'name': _('Time Off'),
|
||||
'project_id': company.leave_timesheet_project_id.id,
|
||||
'active': False,
|
||||
'company_id': False,
|
||||
'company_id': company.id,
|
||||
})
|
||||
company.write({
|
||||
'leave_timesheet_task_id': task.id,
|
||||
|
||||
@@ -7,5 +7,5 @@ from odoo import fields, models
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
leave_timesheet_project_id = fields.Many2one(related='company_id.leave_timesheet_project_id', string="Internal Project", readonly=False)
|
||||
leave_timesheet_task_id = fields.Many2one(related='company_id.leave_timesheet_task_id', string="Time Off Task", readonly=False)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user