diff --git a/addons/project_timesheet_holidays/models/__init__.py b/addons/project_timesheet_holidays/models/__init__.py index 61a9dde07a718..4dee358245f00 100644 --- a/addons/project_timesheet_holidays/models/__init__.py +++ b/addons/project_timesheet_holidays/models/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import res_company # has to be before hr_holidays to create needed columns on res.company from . import account_analytic from . import hr_holidays from . import res_config_settings -from . import res_company diff --git a/addons/project_timesheet_holidays/models/hr_holidays.py b/addons/project_timesheet_holidays/models/hr_holidays.py index d71ece9631b5b..2d245e834d9f5 100644 --- a/addons/project_timesheet_holidays/models/hr_holidays.py +++ b/addons/project_timesheet_holidays/models/hr_holidays.py @@ -8,9 +8,17 @@ class HolidaysType(models.Model): _inherit = "hr.holidays.status" + def _default_project_id(self): + company = self.company_id if self.company_id else self.env.user.company_id + return company.leave_timesheet_project_id.id + + def _default_task_id(self): + company = self.company_id if self.company_id else self.env.user.company_id + return company.leave_timesheet_task_id.id + 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)]") + timesheet_project_id = fields.Many2one('project.project', string="Internal Project", default=_default_project_id, 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", default=_default_task_id, domain="[('project_id', '=', timesheet_project_id)]") @api.onchange('timesheet_generate') def _onchange_timesheet_generate(self): diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py index f98817fdeecd6..9d358c14114a0 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py @@ -6,9 +6,24 @@ from odoo import fields +from odoo.tests import common from odoo.addons.hr_timesheet.tests.test_timesheet import TestTimesheet +class TestTimesheetHolidaysCreate(common.TransactionCase): + + def test_status_create(self): + """Ensure that when a status is created, it fullfills the project and task constrains""" + status = self.env['hr.holidays.status'].create({ + 'name': 'A nice Leave Type', + 'limit': True + }) + + company = self.env.user.company_id + self.assertEqual(status.timesheet_project_id, company.leave_timesheet_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') + + class TestTimesheetHolidays(TestTimesheet): def setUp(self):