Skip to content

Commit

Permalink
[IMP] resource_multi_week_calendar: Add convenience function
Browse files Browse the repository at this point in the history
I need this elsewhere. It _technically_ reduces performance by doing the
same calculation twice, but this module is horrible as pertains to
performance in any case.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Sep 3, 2024
1 parent a9fdc47 commit 05e4d5e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions resource_multi_week_calendar/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def _get_week_number(self, day=None):
)
return (weeks_since_epoch % family_size) + 1

def _get_calendar(self, day=None):
self.ensure_one()
if not self.is_multi_week:
return self
week_number = self._get_week_number(day=day)
return self.family_calendar_ids.filtered(
lambda item: item.week_number == week_number
)

@api.depends(
"multi_week_epoch_date",
"week_number",
Expand All @@ -153,9 +162,7 @@ def _compute_current_week(self):
for calendar in self:
current_week_number = calendar._get_week_number()
calendar.current_week_number = current_week_number
calendar.current_calendar_id = calendar.family_calendar_ids.filtered(
lambda item: item.week_number == current_week_number
)
calendar.current_calendar_id = calendar._get_calendar()

@api.constrains("parent_calendar_id", "child_calendar_ids")
def _check_child_is_not_parent(self):
Expand Down Expand Up @@ -215,7 +222,6 @@ def _split_into_weeks(self, start_dt, end_dt):
# Move to the next week (start of next Monday)
current_start = current_end


def _attendance_intervals(self, start_dt, end_dt, resource=None):
self.ensure_one()
if not self.is_multi_week:
Expand Down

0 comments on commit 05e4d5e

Please sign in to comment.