diff --git a/hr_timesheet_sheet_autodraft/models/account_analytic_line.py b/hr_timesheet_sheet_autodraft/models/account_analytic_line.py index 150800097d..d56045c2eb 100644 --- a/hr_timesheet_sheet_autodraft/models/account_analytic_line.py +++ b/hr_timesheet_sheet_autodraft/models/account_analytic_line.py @@ -44,6 +44,7 @@ def _get_autodraft_sheet_values(self): self.company_id, self.date ), "date_end": HrTimesheetSheet._get_period_end(self.company_id, self.date), + "department_id": self.employee_id.department_id.id, } def action_autodraft_timesheet_sheets(self): diff --git a/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py b/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py index 9f2645fda0..958ace8e25 100644 --- a/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py +++ b/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py @@ -11,6 +11,7 @@ def setUp(self): self.ResUsers = self.env["res.users"] self.Company = self.env["res.company"] self.Project = self.env["project.project"] + self.HrDepartment = self.env["hr.department"] self.HrEmployee = self.env["hr.employee"] self.HrTimesheetSheet = self.env["hr_timesheet.sheet"] self.AccountAnalyticLine = self.env["account.analytic.line"] @@ -43,7 +44,10 @@ def test_autocreate(self): "company_id": self.company_id.id, } ) - employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + department = self.HrDepartment.create({"name": "Department 1"}) + employee = self.HrEmployee.create( + {"name": "Employee", "user_id": user.id, "department_id": department.id} + ) project = self.Project.create({"name": "Project"}) aal_1 = self.AccountAnalyticLine.create( @@ -67,6 +71,7 @@ def test_autocreate(self): self.assertTrue(aal_1.sheet_id) self.assertTrue(aal_2.sheet_id) self.assertEqual(aal_1.sheet_id, aal_2.sheet_id) + self.assertEqual(aal_1.sheet_id.department_id, employee.department_id) def test_already_confirmed(self): user = self.ResUsers.sudo().create(