Skip to content

Commit

Permalink
[IMP] hr_employee_calendar_planning: Set calendars if created from an…
Browse files Browse the repository at this point in the history
… hr job to avoid error

TT44093
  • Loading branch information
victoralmau committed Jun 29, 2023
1 parent 7261e0a commit c654097
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hr_employee_calendar_planning/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,30 @@ def _sync_user(self, user):

@api.model_create_multi
def create(self, vals_list):
# Set calendars if created from an hr job to avoid error
if (
self.env.context.get("active_model", "hr.job")
and self.env.context.get("active_id")
and not self.env.context.get("skip_employee_calendars_required")
):
for vals in vals_list:
if not vals.get("calendar_ids"):
vals["calendar_ids"] = [
(
0,
0,
{"calendar_id": self.env.company.resource_calendar_id.id},
),
]
res = super().create(vals_list)
# Avoid creating an employee without calendars
if (
not self.env.context.get("skip_employee_calendars_required")
and not config["test_enable"]
and res.filtered(lambda x: not x.calendar_ids)
):
raise UserError(_("You can not create employees without any calendars."))
# Regenerate calendar
res.filtered("calendar_ids").regenerate_calendar()
return res

Expand Down

0 comments on commit c654097

Please sign in to comment.