-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] hr_period_create_timesheet: do not create timesheets for employ…
…ees whose contract has not started
- Loading branch information
1 parent
b2d6a16
commit ed6e5bd
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,52 @@ def setUp(self): | |
"company_id": self.company_id.id, | ||
} | ||
) | ||
# create another User | ||
self.user_test_2 = self.user_model.create( | ||
{ | ||
"name": "User 2", | ||
"login": "[email protected]", | ||
"password": "base-test-passwd", | ||
} | ||
) | ||
# create another Employee | ||
self.employee_2 = self.hr_employee.create( | ||
{ | ||
"name": "Employee 2", | ||
"user_id": self.user_test_2.id, | ||
"address_id": self.user_test_2.partner_id.id, | ||
"parent_id": self.root.id, | ||
"company_id": self.company_id.id, | ||
} | ||
) | ||
# create contracts only open for the first employee | ||
self.contract1 = self.env["hr.contract"].create( | ||
{ | ||
"name": "Contract 1", | ||
"employee_id": self.employee.id, | ||
"wage": 1000, | ||
"date_start": time.strftime("%Y-01-01"), | ||
"date_end": time.strftime("%Y-12-31"), | ||
"state": "open", | ||
"resource_calendar_id": self.env["resource.calendar"].browse([1]).id, | ||
} | ||
) | ||
current_year = datetime.now().year | ||
new_year = current_year + 1 | ||
date_start = datetime(new_year, 1, 1).strftime("%Y-%m-%d") | ||
date_end = datetime(new_year, 12, 31).strftime("%Y-%m-%d") | ||
# Creating the contract | ||
self.contract2 = self.env["hr.contract"].create( | ||
{ | ||
"name": "Contract 2", | ||
"employee_id": self.employee_2.id, | ||
"wage": 1000, | ||
"date_start": date_start, | ||
"date_end": date_end, | ||
"state": "open", | ||
"resource_calendar_id": self.env["resource.calendar"].browse([1]).id, | ||
} | ||
) | ||
|
||
def create_data_range_type(self, name): | ||
# create Data Range Type | ||
|
@@ -167,3 +213,12 @@ def test_create_periods_future(self): | |
periods_left = last_period.date_end.month - datetime.now().month + 1 | ||
# timesheets for the rest of the year | ||
self.assertEqual(len(timesheets), periods_left) | ||
# check no timesheet created for the employee whose contract has not started | ||
timesheets = self.timesheet_sheet.search( | ||
[ | ||
("employee_id", "=", self.employee_2.id), | ||
("date_end", ">", datetime.now()), | ||
("company_id", "=", periods[0].company_id.id), | ||
] | ||
) | ||
self.assertEqual(len(timesheets), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters