From 40d9249f90397faae7b3a783ebb11fecae9703db Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 7 Sep 2022 11:35:40 +0000 Subject: [PATCH] [FIX] hr_work_entry_contract: Fix multi-company work entries generation closes odoo/odoo#99760 X-original-commit: f32cb46f18a5ea28b39b29c3c7934656d6af72a0 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_work_entry_contract/models/hr_employee.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/hr_work_entry_contract/models/hr_employee.py b/addons/hr_work_entry_contract/models/hr_employee.py index 05e8edc7fb7..235c6e6317b 100644 --- a/addons/hr_work_entry_contract/models/hr_employee.py +++ b/addons/hr_work_entry_contract/models/hr_employee.py @@ -1,6 +1,7 @@ # -*- coding:utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from collections import defaultdict from odoo import fields, models @@ -17,4 +18,12 @@ class HrEmployee(models.Model): else: current_contracts = self._get_all_contracts(date_start, date_stop, states=['open', 'close']) - return bool(current_contracts._generate_work_entries(date_start, date_stop, force)) + new_work_entries = False + contracts_by_company = defaultdict(lambda: self.env['hr.contract']) + for contract in current_contracts: + contracts_by_company[contract.company_id] |= contract + + for company, contracts in contracts_by_company.items(): + new_work_entries = bool(contracts.with_company(company)._generate_work_entries( + date_start, date_stop, force)) or new_work_entries + return new_work_entries