From 34d54bc87d5553e38445253a49a5e267ac283d17 Mon Sep 17 00:00:00 2001 From: hugues de keyzer Date: Fri, 18 Sep 2026 16:14:06 +0200 Subject: [PATCH] [OU-FIX] hr_contract: fix value of hr_employee.contract_id fix the query setting the values of hr_employee.contract_id: have one row per employee instead of just one row in the sub-query. --- addons/hr_contract/migrations/13.0.1.0/post-migration.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/hr_contract/migrations/13.0.1.0/post-migration.py b/addons/hr_contract/migrations/13.0.1.0/post-migration.py index af7d4e399ee9..45244eb79971 100644 --- a/addons/hr_contract/migrations/13.0.1.0/post-migration.py +++ b/addons/hr_contract/migrations/13.0.1.0/post-migration.py @@ -28,10 +28,11 @@ def fill_employee_contract_id(env): UPDATE hr_employee he SET contract_id = sub.contract_id FROM ( - SELECT he.id AS employee_id, hc.id as contract_id + SELECT DISTINCT ON (employee_id) + he.id AS employee_id, hc.id as contract_id FROM hr_contract hc, hr_employee he WHERE he.id = hc.employee_id AND hc.state = 'open' - LIMIT 1 + ORDER BY employee_id, hc.date_start DESC ) sub WHERE sub.employee_id = he.id AND he.contract_id IS NULL """