From a11ad49230132fb7831514d967f0f518d2b1c4b2 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Tue, 17 Oct 2023 12:29:21 +0200 Subject: [PATCH] Update hr_job_category/models/hr.py Co-authored-by: Florent Xicluna <142113+florentx@users.noreply.github.com> --- hr_job_category/models/hr.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hr_job_category/models/hr.py b/hr_job_category/models/hr.py index 75af0f4a59c..8ae7d54ac96 100644 --- a/hr_job_category/models/hr.py +++ b/hr_job_category/models/hr.py @@ -77,11 +77,13 @@ def write(self, vals): return res def unlink(self): - prev_data = self.read(["job_id"]) - # Go through each record and delete tags associated with the previous - # job, then add the tags of the new job. - # + prev_data = { + res["id"]: res["job_id"][0] + for res in self.read(["job_id"]) if res["job_id"] + } + # Go through each record and delete tags associated with the previous job for contract in self: - for data in prev_data: - self._remove_tags(contract.employee_id.id, data["job_id"][0]) - return super(HRContract, self).unlink() + job_id = prev_data.get(contract.id) + if job_id: + contract._remove_tags(job_id) + return super().unlink()