Skip to content

Commit

Permalink
Merge pull request #77 from RedTurtle/duration_minutes
Browse files Browse the repository at this point in the history
feat!: duration in minutes
  • Loading branch information
cekk authored Aug 24, 2023
2 parents 344d51e + 0475d0f commit c20eca1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Changelog
- Remove unused unavailable_gates field.
[cekk]

- duration in minutes instead of days
[mamico]

- allow to add out-of-office in api (aka blocco prenotazione)
[mamico]

2.0.0.dev4 (2023-08-11)
-----------------------

Expand Down
8 changes: 5 additions & 3 deletions src/redturtle/prenotazioni/adapters/booker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import math
from datetime import timedelta
from plone import api
from plone.memoize.instance import memoize
Expand Down Expand Up @@ -82,8 +83,9 @@ def _create(self, data, duration=-1, force_gate=""):
minutes=duration
)
else:
# in this case we need to deal with seconds converted in days
booking_expiration_date = params["booking_date"] + timedelta(days=duration)
booking_expiration_date = params["booking_date"] + timedelta(
minutes=duration
)

gate = ""
if not force_gate:
Expand Down Expand Up @@ -255,7 +257,7 @@ def create_vacation(self, data):
for slot in gate_free_slots:
if vacation_slot.overlaps(slot):
# there is a slot that overlaps with the vacation
duration = (end - start).seconds / 24 / 60 / 60
duration = math.ceil((end - start).seconds / 60)
# XXX: weird to remove the gate from data and then force it ...
slot_data = {k: v for k, v in data.items() if k != "gate"}
slot_data["booking_date"] = start
Expand Down
3 changes: 1 addition & 2 deletions src/redturtle/prenotazioni/browser/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ def do_book(self, data):
for slot in slots:
booking_date = start_date + (float(slot.lower_value) / 86400)
slot.__class__ = BaseSlot
duration = float(len(slot)) / 86400
# duration = float(len(slot)) / 60
duration = len(slot) / 60
slot_data = {k: v for k, v in data.items() if k != "gate"}
slot_data["booking_date"] = booking_date
booker.create(slot_data, duration=duration, force_gate=data.get("gate"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from redturtle.prenotazioni.interfaces import (
ISerializeToPrenotazioneSearchableItem,
)
from redturtle.prenotazioni import logger
from zope.component import adapter
from zope.i18n import translate
from zope.interface import implementer
Expand All @@ -30,7 +31,17 @@ def __call__(self, *args, **kwargs):
status = api.portal.get_tool("portal_workflow").getStatusOf(
"prenotazioni_workflow", self.prenotazione
)

booking_date = self.prenotazione.booking_date
booking_expiration_date = self.prenotazione.booking_expiration_date
if (
booking_expiration_date
and booking_date.date() != booking_expiration_date.date()
):
logger.warning("Booking date and expiration date are different, fixing")
booking_date = booking_date.date()
booking_expiration_date = booking_expiration_date.replace(
booking_date.year, booking_date.month, booking_date.day
)
return {
"UID": self.prenotazione.UID(),
"@type": self.prenotazione.portal_type,
Expand All @@ -43,10 +54,8 @@ def __call__(self, *args, **kwargs):
"fiscalcode": fiscalcode,
"company": self.prenotazione.company,
"staff_notes": self.prenotazione.staff_notes,
"booking_date": json_compatible(self.prenotazione.booking_date),
"booking_expiration_date": json_compatible(
self.prenotazione.booking_expiration_date
),
"booking_date": json_compatible(booking_date),
"booking_expiration_date": json_compatible(booking_expiration_date),
"booking_status_label": translate(
status["review_state"], context=self.request
),
Expand Down
6 changes: 5 additions & 1 deletion src/redturtle/prenotazioni/restapi/services/booking/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from plone.restapi.interfaces import ISerializeToJson
from redturtle.prenotazioni import _
from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.content.prenotazione import VACATION_TYPE
from redturtle.prenotazioni.restapi.services.booking_schema.get import BookingSchema
from zExceptions import BadRequest
from zope.component import queryMultiAdapter
Expand Down Expand Up @@ -82,7 +83,10 @@ def validate(self):
)
raise BadRequest(msg)

if data["booking_type"] not in [
if data["booking_type"] in [VACATION_TYPE]:
# TODO: check permission for special booking_types ?
pass
elif data["booking_type"] not in [
_t["name"] for _t in self.context.booking_types or [] if "name" in _t
]:
msg = self.context.translate(
Expand Down
2 changes: 2 additions & 0 deletions src/redturtle/prenotazioni/restapi/services/booking/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def reply(self):
return self.reply_no_content(status=404)

booker = IBooker(booking.getPrenotazioniFolder())

# TODO: gestire eccezioni nel caso ci sia sovrapposizione
booker.move(booking=booking, data=data)

alsoProvides(self.request, IDisableCSRFProtection)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-

# #### DEPRECATED ####

from plone.protect.interfaces import IDisableCSRFProtection
from plone.restapi.deserializer import json_body
from plone.restapi.services import Service
Expand Down

0 comments on commit c20eca1

Please sign in to comment.