Skip to content

Commit

Permalink
[FIX] hr_period_create_timesheet: do not create timesheets for employ…
Browse files Browse the repository at this point in the history
…ees whose contract has not started
  • Loading branch information
AaronHForgeFlow committed Nov 19, 2024
1 parent b2d6a16 commit ed6e5bd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def create_timesheets_on_future_periods(self):
timesheet_obj = self.env["hr_timesheet.sheet"]
today = fields.Date.today()
periods = self.env["hr.period"].search([("date_end", ">=", today)])
employees = self.env["hr.employee"].search([("user_id", "!=", False)])
employees = self.env["hr.employee"].search(
[("user_id", "!=", False), ("contract_id.date_start", "<=", today)]
)
if not periods or not employees:
return
# Create a dictionary to store existing timesheets per employee
Expand Down

0 comments on commit ed6e5bd

Please sign in to comment.