Skip to content

Commit

Permalink
Update booking limit message + labels
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 4, 2023
1 parent 0d2bdd8 commit d759be9
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 335 deletions.
15 changes: 6 additions & 9 deletions src/redturtle/prenotazioni/adapters/booker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from zope.component import Interface
from zope.event import notify
from zope.interface import implementer
from ZTUtils.Lazy import LazyMap

from redturtle.prenotazioni import _, datetime_with_tz, logger
from redturtle.prenotazioni.adapters.slot import BaseSlot
Expand Down Expand Up @@ -62,11 +63,12 @@ def _validate_user_limit(self, data: dict):
data["fiscalcode"], data["booking_type"]
)
) >= (self.context.max_bookings_allowed):
raise BookingsLimitExceded(self.context)
raise BookingsLimitExceded(self.context, booking_type=data["booking_type"])

def search_future_bookings_by_fiscalcode(self, fiscalcode, booking_type=None):
def search_future_bookings_by_fiscalcode(
self, fiscalcode: str, booking_type: str = None
) -> LazyMap:
"""Find all the future bookings registered for the same fiscalcode"""
result = []
query = dict(
portal_type="Prenotazione",
fiscalcode=fiscalcode,
Expand All @@ -80,12 +82,7 @@ def search_future_bookings_by_fiscalcode(self, fiscalcode, booking_type=None):
if booking_type:
query["booking_type"] = booking_type

for booking in api.portal.get_tool("portal_catalog").unrestrictedSearchResults(
**query
):
result.append(booking)

return result
return api.portal.get_tool("portal_catalog").unrestrictedSearchResults(**query)

def get_available_gate(self, booking_date, booking_expiration_date=None):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,10 @@ def data_validation(data):
),
description=_(
"max_bookings_allowed_description",
default="Number of simultaneous bookins allowed for the same user.",
default="The number of simultaneous bookings allowed for the same user.",
),
required=False,
default=2,
)

model.fieldset(
Expand Down
9 changes: 6 additions & 3 deletions src/redturtle/prenotazioni/exceptions/booker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ class BookerException(Exception):


class BookingsLimitExceded(BookerException):
def __init__(self, bookings_folder=None, *args, **kwargs):
def __init__(self, bookings_folder, booking_type, *args, **kwargs):
return super().__init__(
api.portal.translate(
_(
"bookings_limit_exceeded_exception",
default="Booking limit({limit}) is exceed for the current user",
default="Booking limit({limit}) for the {booking_type} type is exceed for the current user",
)
).format(limit=bookings_folder.max_bookings_allowed),
).format(
limit=bookings_folder.max_bookings_allowed,
booking_type=booking_type,
),
*args,
**kwargs
)
Loading

0 comments on commit d759be9

Please sign in to comment.