diff --git a/addons/hr_work_entry_contract/models/hr_contract.py b/addons/hr_work_entry_contract/models/hr_contract.py index e396c0c9e4e..0c97247431a 100644 --- a/addons/hr_work_entry_contract/models/hr_contract.py +++ b/addons/hr_work_entry_contract/models/hr_contract.py @@ -364,7 +364,7 @@ class HrContract(models.Model): def _recompute_work_entries(self, date_from, date_to): self.ensure_one() wizard = self.env['hr.work.entry.regeneration.wizard'].create({ - 'employee_id': self.employee_id.id, + 'employee_ids': [(4, self.employee_id.id)], 'date_from': date_from, 'date_to': date_to, }) diff --git a/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard.py b/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard.py index 27e043c7c48..cc6928d15b1 100644 --- a/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard.py +++ b/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard.py @@ -17,7 +17,7 @@ class HrWorkEntryRegenerationWizard(models.TransientModel): date_from = fields.Date('From', required=True, default=lambda self: self.env.context.get('date_start')) date_to = fields.Date('To', required=True, compute='_compute_date_to', store=True, readonly=False, default=lambda self: self.env.context.get('date_end')) - employee_id = fields.Many2one('hr.employee', 'Employee', required=True) + employee_ids = fields.Many2many('hr.employee', string='Employees', required=True) validated_work_entry_ids = fields.Many2many('hr.work.entry', string='Work Entries Within Interval', compute='_compute_validated_work_entry_ids') search_criteria_completed = fields.Boolean(compute='_compute_search_criteria_completed') @@ -28,26 +28,26 @@ class HrWorkEntryRegenerationWizard(models.TransientModel): for wizard in self: wizard.date_to = wizard.date_from + relativedelta(months=+1, day=1, days=-1) - @api.depends('employee_id') + @api.depends('employee_ids') def _compute_earliest_available_date(self): for wizard in self: - dates = wizard.mapped('employee_id.contract_ids.date_generated_from') + dates = wizard.employee_ids.contract_ids.mapped('date_generated_from') wizard.earliest_available_date = min(dates) if dates else None - @api.depends('employee_id') + @api.depends('employee_ids') def _compute_latest_available_date(self): for wizard in self: - dates = wizard.mapped('employee_id.contract_ids.date_generated_to') + dates = wizard.employee_ids.contract_ids.mapped('date_generated_to') wizard.latest_available_date = max(dates) if dates else None - @api.depends('date_from', 'date_to', 'employee_id') + @api.depends('date_from', 'date_to', 'employee_ids') def _compute_validated_work_entry_ids(self): for wizard in self: validated_work_entry_ids = self.env['hr.work.entry'] if wizard.search_criteria_completed: - search_domain = [('employee_id', '=', self.employee_id.id), - ('date_start', '>=', self.date_from), - ('date_stop', '<=', self.date_to), + search_domain = [('employee_id', 'in', wizard.employee_ids.ids), + ('date_start', '>=', wizard.date_from), + ('date_stop', '<=', wizard.date_to), ('state', '=', 'validated')] validated_work_entry_ids = self.env['hr.work.entry'].search(search_domain, order="date_start") wizard.validated_work_entry_ids = validated_work_entry_ids @@ -57,12 +57,12 @@ class HrWorkEntryRegenerationWizard(models.TransientModel): for wizard in self: wizard.valid = wizard.search_criteria_completed and len(wizard.validated_work_entry_ids) == 0 - @api.depends('date_from', 'date_to', 'employee_id') + @api.depends('date_from', 'date_to', 'employee_ids') def _compute_search_criteria_completed(self): for wizard in self: - wizard.search_criteria_completed = wizard.date_from and wizard.date_to and wizard.employee_id and wizard.earliest_available_date and wizard.latest_available_date + wizard.search_criteria_completed = wizard.date_from and wizard.date_to and wizard.employee_ids and wizard.earliest_available_date and wizard.latest_available_date - @api.onchange('date_from', 'date_to', 'employee_id') + @api.onchange('date_from', 'date_to', 'employee_ids') def _check_dates(self): for wizard in self: wizard.earliest_available_date_message = '' @@ -103,11 +103,11 @@ class HrWorkEntryRegenerationWizard(models.TransientModel): date_from = max(self.date_from, self.earliest_available_date) if self.earliest_available_date else self.date_from date_to = min(self.date_to, self.latest_available_date) if self.latest_available_date else self.date_to work_entries = self.env['hr.work.entry'].search([ - ('employee_id', '=', self.employee_id.id), + ('employee_id', 'in', self.employee_ids.ids), ('date_stop', '>=', date_from), ('date_start', '<=', date_to), ('state', '!=', 'validated')]) write_vals = {field: False for field in self._work_entry_fields_to_nullify()} work_entries.write(write_vals) - self.employee_id.generate_work_entries(date_from, date_to, True) + self.employee_ids.generate_work_entries(date_from, date_to, True) diff --git a/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard_views.xml b/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard_views.xml index 29da1ba9a68..ef450db18ef 100644 --- a/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard_views.xml +++ b/addons/hr_work_entry_contract/wizard/hr_work_entry_regeneration_wizard_views.xml @@ -7,7 +7,7 @@