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 e363470 commit 698f076
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 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

0 comments on commit 698f076

Please sign in to comment.