[IMP] project_timesheet_holidays: set project and task of the time-off type's company
Before this commit, the project and task fields were not dependent on the company. The default project was set as the company if it existed; otherwise, it was retrieved from the environment, and the internal project was set as the default. The task was computed based on the project. In this commit, the project will only be set to its internal project if the company exists. If the company is false or not specified, both project and task will be set to false. task-3279188 closes odoo/odoo#129539 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<function model="hr.leave" name="_remove_resource_leave">
|
||||
<value eval="[ref('hr_holidays.hr_holidays_sl'), ref('hr_holidays.hr_holidays_cl_qdp'), ref('hr_holidays.hr_holidays_sl_qdp')]"/>
|
||||
</function>
|
||||
<function model="hr.leave" name="_timesheet_create_lines">
|
||||
<function model="hr.leave" name="_validate_leave_request">
|
||||
<value eval="[ref('hr_holidays.hr_holidays_sl'), ref('hr_holidays.hr_holidays_cl_qdp'), ref('hr_holidays.hr_holidays_sl_qdp')]"/>
|
||||
</function>
|
||||
<function model="hr.leave" name="_create_resource_leave">
|
||||
|
||||
@@ -8,21 +8,14 @@ from odoo.exceptions import ValidationError
|
||||
class HolidaysType(models.Model):
|
||||
_inherit = "hr.leave.type"
|
||||
|
||||
def _default_project_id(self):
|
||||
company = self.company_id if self.company_id else self.env.company
|
||||
return company.internal_project_id.id
|
||||
|
||||
def _default_task_id(self):
|
||||
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', 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)]")
|
||||
timesheet_project_id = fields.Many2one('project.project', string="Project", domain="[('company_id', '=', company_id)]",
|
||||
compute="_compute_timesheet_project_id", store=True, readonly=False)
|
||||
timesheet_task_id = fields.Many2one(
|
||||
'project.task', string="Task", compute='_compute_timesheet_task_id',
|
||||
store=True, readonly=False, default=_default_task_id,
|
||||
store=True, readonly=False,
|
||||
domain="[('project_id', '=', timesheet_project_id),"
|
||||
"('project_id', '!=', False),"
|
||||
"('company_id', '=', company_id)]")
|
||||
@@ -32,11 +25,15 @@ class HolidaysType(models.Model):
|
||||
for leave_type in self:
|
||||
leave_type.timesheet_generate = leave_type.timesheet_task_id and leave_type.timesheet_project_id
|
||||
|
||||
@api.depends('company_id')
|
||||
def _compute_timesheet_project_id(self):
|
||||
for leave in self:
|
||||
leave.timesheet_project_id = leave.company_id.internal_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
|
||||
default_task_id = leave_type.company_id.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
|
||||
@@ -46,7 +43,7 @@ class HolidaysType(models.Model):
|
||||
@api.constrains('timesheet_generate', 'timesheet_project_id', 'timesheet_task_id')
|
||||
def _check_timesheet_generate(self):
|
||||
for holiday_status in self:
|
||||
if holiday_status.timesheet_generate:
|
||||
if holiday_status.timesheet_generate and holiday_status.company_id:
|
||||
if not holiday_status.timesheet_project_id or not holiday_status.timesheet_task_id:
|
||||
raise ValidationError(_("Both the internal project and task are required to "
|
||||
"generate a timesheet for the time off %s. If you don't want a timesheet, you should "
|
||||
|
||||
@@ -22,9 +22,8 @@ class TestTimesheetHolidaysCreate(common.TransactionCase):
|
||||
'requires_allocation': 'no'
|
||||
})
|
||||
|
||||
company = self.env.company
|
||||
self.assertEqual(status.timesheet_project_id, company.internal_project_id, 'The default project linked to the status should be the same as the company')
|
||||
self.assertEqual(status.timesheet_task_id, company.leave_timesheet_task_id, 'The default task linked to the status should be the same as the company')
|
||||
self.assertEqual(status.timesheet_project_id, status.company_id.internal_project_id, 'The default project linked to the status should be the same as the company')
|
||||
self.assertEqual(status.timesheet_task_id, status.company_id.leave_timesheet_task_id, 'The default task linked to the status should be the same as the company')
|
||||
|
||||
def test_company_create(self):
|
||||
main_company = self.env.ref('base.main_company')
|
||||
|
||||
Reference in New Issue
Block a user