Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unavailable gates #81

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
2.0.0rc2 (unreleased)
---------------------

- Show default gates as unavailable in get_gates method, if they are overrided.
[cekk]
- Skip required field validation when add out of office bookings in @booking endpoint.
[cekk]
- Only users with permission can add out of office bookings in @booking endpoint.
Expand Down
33 changes: 28 additions & 5 deletions src/redturtle/prenotazioni/browser/prenotazioni_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,42 @@ def get_gates(self, booking_date=None):
# sometimes booking_date is passed as date and sometimes as datetime
booking_date = booking_date.date()

gates = self.context.getGates()
gates = [
{
"name": gate,
"available": True,
}
for gate in self.context.getGates() or [""]
]

overrides = self.get_week_overrides(day=booking_date)
if overrides:
gates = overrides.get("gates", []) or gates
if not overrides:
return gates

return [
overrided_gates = overrides.get("gates", [])
if not overrided_gates:
return gates

overrided_gates = [
{
"name": gate,
"available": True,
}
for gate in gates or [""]
for gate in overrided_gates or [""]
]

# set default gates as unavailable
gates = [
{
"name": gate["name"],
"available": False,
}
for gate in gates
if gate["name"] not in [i["name"] for i in overrided_gates]
]

return gates + overrided_gates

def get_busy_gates_in_slot(self, booking_date, booking_end_date=None):
"""
The gates already associated to a Prenotazione object for booking_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def reply(self):
If not, the search will start from current date until the end of current month.
"""
prenotazioni_week_view = api.content.get_view(
"prenotazioni_week_view", context=self.context, request=self.request
"prenotazioni_week_view",
context=self.context,
request=self.request,
)
start = self.request.form.get("start", "")
end = self.request.form.get("end", "")
Expand Down
8 changes: 6 additions & 2 deletions src/redturtle/prenotazioni/tests/test_available_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.testing import RelativeSession
from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.testing import REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING,
)

import calendar
import pytz
Expand Down Expand Up @@ -57,7 +59,9 @@ def setUp(self):
self.folder_prenotazioni.week_table = week_table

year = api.content.create(
container=self.folder_prenotazioni, type="PrenotazioniYear", title="Year"
container=self.folder_prenotazioni,
type="PrenotazioniYear",
title="Year",
)
week = api.content.create(container=year, type="PrenotazioniWeek", title="Week")
self.day_folder = api.content.create(
Expand Down
27 changes: 21 additions & 6 deletions src/redturtle/prenotazioni/tests/test_gates_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from datetime import date
from plone import api
from plone.app.testing import TEST_USER_ID, setRoles
from redturtle.prenotazioni.testing import REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING,
)
from redturtle.prenotazioni.tests.helpers import WEEK_TABLE_SCHEMA

import json
Expand All @@ -27,15 +29,15 @@ def setUp(self):
booking_types=[
{"name": "Type A", "duration": "30"},
],
gates=["Gate A"],
gates=["Gate A", "Gate B"],
week_table=WEEK_TABLE_SCHEMA,
week_table_overrides=json.dumps(
[
{
"from_day": "1",
"from_month": "1",
"to_month": "2",
"gates": ["foo", "bar"],
"gates": ["Gate B", "foo", "bar"],
"to_day": "18",
"week_table": [],
"pause_table": [],
Expand All @@ -52,18 +54,31 @@ def setUp(self):
request=self.request,
)

def test_day_in_override_gates(self):
def test_day_in_override_gates_return_overrided_gates_available_and_default_unavailable(
self,
):
now = date.today()
gates = self.view.get_gates(date(now.year, 1, 10))
self.assertEqual(
gates,
[{"name": "foo", "available": True}, {"name": "bar", "available": True}],
[
{"name": "Gate A", "available": False},
{"name": "Gate B", "available": True},
{"name": "foo", "available": True},
{"name": "bar", "available": True},
],
)

def test_day_not_in_override_gates(self):
now = date.today()
gates = self.view.get_gates(date(now.year, 6, 10))
self.assertEqual(gates, [{"name": "Gate A", "available": True}])
self.assertEqual(
gates,
[
{"name": "Gate A", "available": True},
{"name": "Gate B", "available": True},
],
)

def test_if_gates_override_not_set_use_default(self):
folder = api.content.create(
Expand Down