From 0053a9e56534be27f822da50cd59634f476f777a Mon Sep 17 00:00:00 2001 From: alt-odoo Date: Fri, 7 Oct 2022 10:51:20 +0000 Subject: [PATCH] [FIX] hr_contract: handle employees with multiple contracts In case an employee has multiple contracts in several companies, we need to only keep the contract of the current company of the employee, as there can be only one in the main view hr_contract_history. Before this patch, contract_information CTE returns the same ID for both contracts: employee_id | company_id | id | is_under_contract -------------+------------+--------+------------------- 681 | 1 | 146842 | 0 681 | 14 | 146842 | 0 After the patch, it returns: employee_id | company_id | id | is_under_contract -------------+------------+--------+------------------- 681 | 1 | 4009 | 0 681 | 14 | 146842 | 0 We need to fix the WINDOW clause to make sure the id of the contract that is selected is the one in the same company as the employee/contract being selected in the contract_information CTE. This way when an employee has multiple contracts, there will still be 1 line for each contract, but each with a different contract ID. closes odoo/odoo#102821 X-original-commit: 88fa430be8a0c164e100b5f3c2f16ae906cc9a54 Signed-off-by: Kevin Baptiste Signed-off-by: Alex Thuyls (alt) --- addons/hr_contract/report/hr_contract_history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_contract/report/hr_contract_history.py b/addons/hr_contract/report/hr_contract_history.py index 128c363a101..fd63409d917 100644 --- a/addons/hr_contract/report/hr_contract_history.py +++ b/addons/hr_contract/report/hr_contract_history.py @@ -87,7 +87,7 @@ class ContractHistory(models.Model): FROM hr_contract AS contract WHERE contract.active = true WINDOW w_partition AS ( - PARTITION BY contract.employee_id + PARTITION BY contract.employee_id, contract.company_id ORDER BY CASE WHEN contract.state = 'open' THEN 0