[REF]l10n_fr_hr_holidays:clean up leave days computation
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m58s
tests / test (pull_request) Successful in 2m25s

- remove unused _round_to_nearest_half
- evaluate _l10n_fr_leave_applies once in _get_number_of_days_batch and
  count working dates without a day-by-day loop
- compute the calendar working hours once per date lookup loop
- move pytz import to the top of resource_calendar.py

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 11:03:52 +01:00
parent 83f2169647
commit 25e1d6b957
2 changed files with 26 additions and 23 deletions

View File

@@ -4,16 +4,22 @@
from collections import defaultdict
from datetime import datetime, time
from pytz import timezone
from odoo import models
class ResourceCalendar(models.Model):
_inherit = 'resource.calendar'
def _works_on_date(self, date):
def _works_on_date(self, date, working_days=None):
"""Return True if the calendar has attendances on the weekday of `date`.
`working_days` can be given (result of `_get_working_hours`) to avoid
recomputing it when called in a loop."""
self.ensure_one()
working_days = self._get_working_hours()
if working_days is None:
working_days = self._get_working_hours()
dayofweek = str(date.weekday())
if self.two_weeks_calendar:
weektype = str(self.env['resource.calendar.attendance'].get_week_type(date))
@@ -34,7 +40,6 @@ class ResourceCalendar(models.Model):
and other global leaves registered on the calendar.
"""
self.ensure_one()
from pytz import timezone
tz = timezone(self.tz or 'UTC')
from_dt = tz.localize(datetime.combine(from_date, time.min))
to_dt = tz.localize(datetime.combine(to_date, time(23, 59, 59)))