[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 <kba@odoo.com> Signed-off-by: Alex Thuyls (alt) <alt@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user