Skip to content

Commit

Permalink
[IMP] hr_employee_calendar_planning: Set calendar_ids default value t…
Browse files Browse the repository at this point in the history
…o cover all use cases

TT44093
  • Loading branch information
victoralmau committed Jun 30, 2023
1 parent 7261e0a commit 94ed880
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hr_employee_calendar_planning/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ class HrEmployee(models.Model):
copy=True,
)

@api.model
def default_get(self, fields):
"""Set calendar_ids default value to cover all use cases."""
vals = super().default_get(fields)
if "calendar_ids" in fields and not vals.get("calendar_ids"):
vals["calendar_ids"] = [
(
0,
0,
{"calendar_id": self.env.company.resource_calendar_id.id},
),
]
return vals

def _regenerate_calendar(self):
self.ensure_one()
vals_list = []
Expand Down Expand Up @@ -142,12 +156,14 @@ def _sync_user(self, user):
@api.model_create_multi
def create(self, vals_list):
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 94ed880

Please sign in to comment.