[FIX] odex_benefit: Fix bug

This commit is contained in:
younes 2025-10-29 08:17:20 +01:00
parent 96335a041a
commit 3722157ea2
1 changed files with 9 additions and 6 deletions

View File

@ -763,12 +763,15 @@ class ServiceRequest(models.Model):
if rec.max_limit_period:
if rec.max_limit_period == "month":
num_months = (rec.end.year - rec.start.year) * 12 + (rec.end.month - rec.start.month) + 1
if num_months > rec.service_cat.max_months_limit:
raise ValidationError(
_("You cannot request this service for more than %s months.") % rec.service_cat.max_months_limit
)
rec.service_max_amount *= num_months
if rec.start and rec.end:
start_date = rec.start.date() if isinstance(rec.start, datetime) else rec.start
end_date = rec.end.date() if isinstance(rec.end, datetime) else rec.end
num_months = (end_date.year - start_date.year) * 12 + (end_date.month - start_date.month) + 1
if num_months > rec.service_cat.max_months_limit:
raise ValidationError(
_("You cannot request this service for more than %s months.") % rec.service_cat.max_months_limit
)
rec.service_max_amount *= num_months
elif rec.max_limit_period == "year":
before_year_domain = base_domain + [('date', '>', date_before_year)]
existing_requests_within_year = Service.search(before_year_domain)