Skip to content

Commit 598be71

Browse files
committed
[FIX] hr_work_entry: Fix work entry type domain in multiselect
Reproduce step: 1. Go to work entries 2. Select some work entries to add using the multiselection in the gantt view. 3. Work entry types doesn't include the ones related to the country. Reason: The country_id is set to False, so the old domain will retrieve only the work entries which are not related to any country. Fix: Update work_entry_type_id domain and make it dynamic which depends on the situation, if we are going to create work entries in the gantt views in multi company situation, we will display the work entries types without a specific country only to avoid issues, since it is possible to select employees from different companies at the same time. In the other case (single company) we filter the work entry types based on the self.env.company.id Related task: 5155691. closes odoo#230746 Signed-off-by: Yannick Tivisse (yti) <[email protected]>
1 parent 5050789 commit 598be71

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

addons/hr_work_entry/models/hr_work_entry.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class HrWorkEntry(models.Model):
2626
work_entry_source = fields.Selection(related='version_id.work_entry_source')
2727
date = fields.Date(required=True)
2828
duration = fields.Float(string="Duration", default=8)
29-
work_entry_type_id = fields.Many2one('hr.work.entry.type', index=True, default=lambda self: self.env['hr.work.entry.type'].search([], limit=1), domain="['|', ('country_id', '=', False), ('country_id', '=', country_id)]")
29+
work_entry_type_id = fields.Many2one(
30+
'hr.work.entry.type',
31+
index=True,
32+
default=lambda self: self.env['hr.work.entry.type'].search([], limit=1),
33+
domain=lambda self: self._get_work_entry_type_domain())
3034
display_code = fields.Char(related='work_entry_type_id.display_code')
3135
code = fields.Char(related='work_entry_type_id.code')
3236
external_code = fields.Char(related='work_entry_type_id.external_code')
@@ -304,3 +308,8 @@ def _error_checking(self, start=None, stop=None, skip=False, employee_ids=False)
304308
# New work entries are handled in the create method,
305309
# no need to reload work entries.
306310
work_entries.exists()._check_if_error()
311+
312+
def _get_work_entry_type_domain(self):
313+
if len(self.env.companies.country_id.ids) > 1:
314+
return [('country_id', '=', False)]
315+
return ['|', ('country_id', '=', False), ('country_id', 'in', self.env.companies.country_id.ids)]

0 commit comments

Comments
 (0)