diff --git a/hr_timesheet_sheet_prefill/models/hr_employee.py b/hr_timesheet_sheet_prefill/models/hr_employee.py index 393051b..3cd86ae 100644 --- a/hr_timesheet_sheet_prefill/models/hr_employee.py +++ b/hr_timesheet_sheet_prefill/models/hr_employee.py @@ -12,11 +12,9 @@ class Employee(models.Model): comodel_name="project.project", relation="hr_employee_project_project_rel", string="Projects", - domain=[("active", "=", True)], ) - # This exists solely extension in hr_timesheet_sheet_prefill_multi, and also - # to filter out inactive projects. + # This exists solely for extension in hr_timesheet_sheet_prefill_multi. def all_prefill_projects(self): self.ensure_one() - return self.project_ids.filtered(lambda project: project.active) + return self.project_ids diff --git a/hr_timesheet_sheet_prefill_multi/models/hr_employee.py b/hr_timesheet_sheet_prefill_multi/models/hr_employee.py index e4eb137..8e01054 100644 --- a/hr_timesheet_sheet_prefill_multi/models/hr_employee.py +++ b/hr_timesheet_sheet_prefill_multi/models/hr_employee.py @@ -16,18 +16,13 @@ class HrEmployee(models.Model): ) def all_prefill_projects(self): - projects = super().all_prefill_projects() - # By searching, we get prefills sorted by sequence. - prefills = self.env["hr_timesheet.sheet.prefill"].search( - [ - ("project_project_id", "in", projects.ids), - ("hr_employee_id", "=", self.id), - ] - ) - # Instead of doing `prefills.mapped("project_project_id")`, we manually - # create the recordset. This is because the recordset MAY contain - # duplicates, and `mapped()` removes duplicates. - result = self.env["project.project"] - for prefill in prefills: - result += prefill.project_project_id - return result + self.ensure_one() + # The only purpose of the below code is to sort the projects according + # to the sequence of the prefill records. Instead of doing + # `self.timesheet_prefill_ids.mapped("project_project_id")`, we + # manually create the recordset. This is because the recordset MAY + # contain duplicates, and `mapped()` removes duplicates. + projects = self.env["project.project"].browse() + for prefill in self.timesheet_prefill_ids: + projects += prefill.project_project_id + return projects diff --git a/hr_timesheet_sheet_prefill_multi/models/hr_timesheet_sheet_prefill.py b/hr_timesheet_sheet_prefill_multi/models/hr_timesheet_sheet_prefill.py index c5660af..bc11156 100644 --- a/hr_timesheet_sheet_prefill_multi/models/hr_timesheet_sheet_prefill.py +++ b/hr_timesheet_sheet_prefill_multi/models/hr_timesheet_sheet_prefill.py @@ -30,8 +30,8 @@ class HrTimesheetSheetPrefill(models.Model): ondelete="cascade", required=True, ) - sequence = fields.Integer(string="Sequence", default=10) + active = fields.Boolean(related="project_project_id.active") @api.model_cr def init(self):