Skip to content

Commit

Permalink
Merge pull request #366 from City-of-Turku/develop
Browse files Browse the repository at this point in the history
Release tku-v1.11
  • Loading branch information
SanttuA authored Jun 4, 2024
2 parents 26ab414 + 39a0353 commit 22c2d93
Show file tree
Hide file tree
Showing 33 changed files with 760 additions and 166 deletions.
36 changes: 31 additions & 5 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,6 @@ msgstr ""
msgid "Reservation metadata sets"
msgstr ""

#: resources/models/reservation.py:674
msgid "Reminder Date"
msgstr ""

#: resources/models/reservation.py:676
msgid "Notification type"
msgstr ""
Expand Down Expand Up @@ -1481,7 +1477,7 @@ msgid "Outlook configuration"
msgstr ""

#: resources/models/resource.py:315
msgid "You cannot make a multi day reservation"
msgid "You cannot make a multiday reservation"
msgstr ""

#: resources/models/resource.py:321
Expand Down Expand Up @@ -2885,5 +2881,35 @@ msgstr ""
msgid "Recurring reservations"
msgstr ""

msgid "Reservation reminders"
msgstr ""

msgid "Reminder date"
msgstr ""

msgid "Cannot be reserved during cooldown"
msgstr ""

msgid "Overnight reservations"
msgstr ""

msgid "Allow overnight reservations for this resource"
msgstr ""

msgid "Overnight start time"
msgstr ""

msgid "Overnight end time"
msgstr ""

msgid "Overnight reservation end time cannot be greater than start time"
msgstr ""

msgid "Search tags"
msgstr ""

msgid "Reservation start and end must match the given overnight reservation start and end values"
msgstr ""

msgid "The reservation deadline is the start time. For example, if the start time is 6:00 PM, same-day bookings must be made before 6:00 PM."
msgstr ""
32 changes: 31 additions & 1 deletion locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ msgid ""
msgstr ""
"Ulkoisen varausjärjestelmän osoite jos tätä resurssia hallitaan muualla"

msgid "You cannot make a multi day reservation"
msgid "You cannot make a multiday reservation"
msgstr "Varaus ei saa ulottua useammalle päivälle"

msgid "You must start and end the reservation during opening hours"
Expand Down Expand Up @@ -2266,5 +2266,35 @@ msgstr "Toistuva varaus"
msgid "Recurring reservations"
msgstr "Toistuvat varaukset"

msgid "Reservation reminders"
msgstr "Varausmuistutukset"

msgid "Reminder date"
msgstr "Muistutuksen päivämäärä"

msgid "Cannot be reserved during cooldown"
msgstr "Varausta ei voi tehdä varaustauon aikana"

msgid "Overnight reservations"
msgstr "Yön yli varaukset"

msgid "Allow overnight reservations for this resource"
msgstr "Salli yön yli varaukset tälle resurssille"

msgid "Overnight start time"
msgstr "Yön yli varauksen aloitusaika"

msgid "Overnight end time"
msgstr "Yön yli varauksen päättymisaika"

msgid "Overnight reservation end time cannot be greater than start time"
msgstr "Yön yli varauksen päättymisaika ei voi olla aloitusaikaa pidempi"

msgid "Search tags"
msgstr "Hakutagit"

msgid "Reservation start and end must match the given overnight reservation start and end values"
msgstr "Varauksen alkamisajan ja päättymisajan on vastattava annettuja yön yli varauksen alkamisajan ja päättymisajan arvoja"

msgid "The reservation deadline is the start time. For example, if the start time is 6:00 PM, same-day bookings must be made before 6:00 PM."
msgstr "Varausten takaraja on aloitusaika. Esim. jos aloitusaika on klo 18.00, saman päivän varaus on tehtävä ennen klo 18.00."
34 changes: 32 additions & 2 deletions locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ msgid "Reservation bulk created"
msgstr "Reservationssats skapad"

msgid "Reservation reminder"
msgstr "Påminnelse om reservation"
msgstr "Bokningspåminnelse"

msgid "Type"
msgstr "Typ"
Expand Down Expand Up @@ -1071,7 +1071,7 @@ msgstr ""
"En URL till ett externt bokningssystem om den här resursen hanteras "
"annorstädes"

msgid "You cannot make a multi day reservation"
msgid "You cannot make a multiday reservation"
msgstr "Du kan inte boka flera dagar"

msgid "You must start and end the reservation during opening hours"
Expand Down Expand Up @@ -2207,5 +2207,35 @@ msgstr "Återkommande bokning"
msgid "Recurring reservations"
msgstr "Återkommande bokningar"

msgid "Reservation reminders"
msgstr "Bokningspåminnelser"

msgid "Reminder date"
msgstr "Påminnelsedatum"

msgid "Cannot be reserved during cooldown"
msgstr "Bokning kan inte göras under bokningsuppehåll"

msgid "Overnight reservations"
msgstr "Övernattning bokningar"

msgid "Allow overnight reservations for this resource"
msgstr "Tillåt övernattning bokningar för denna resurs"

msgid "Overnight start time"
msgstr "Starttid för övernattning"

msgid "Overnight end time"
msgstr "Sluttid för övernattning"

msgid "Overnight reservation end time cannot be greater than start time"
msgstr "Sluttiden för övernattning kan inte vara senare än starttiden"

msgid "Search tags"
msgstr "Sök taggar"

msgid "Reservation start and end must match the given overnight reservation start and end values"
msgstr "Reservationsstart och reservationsslut måste överensstämma med de angivna värdena för start och slut på övernattningen"

msgid "The reservation deadline is the start time. For example, if the start time is 6:00 PM, same-day bookings must be made before 6:00 PM."
msgstr "Bokningsfristen är starttiden. Till exempel, om starttiden är 18.00, måste bokningar för samma dag göras före 18.00."
7 changes: 7 additions & 0 deletions payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ def save(self, *args, **kwargs):
def delete(self, *args, **kwargs):
Product.objects.filter(id=self.id).update(archived_at=now())

def fmt_price_period(self):
total = int(self.price_period.total_seconds())
hours = total // 3600
minutes = (total % 3600) // 60
seconds = total % 60
return f"{hours:02}:{minutes:02}:{seconds:02}"

@rounded
def get_pretax_price(self) -> Decimal:
return convert_aftertax_to_pretax(self.price, self.tax_percentage)
Expand Down
116 changes: 116 additions & 0 deletions payments/tests/test_reservation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,3 +994,119 @@ def test_reservation_waiting_for_payment_sent_only_once(resource_with_manual_con
assert response.status_code == 200
assert response.data['state'] == Reservation.READY_FOR_PAYMENT
assert len(mail.outbox) == 0


@override_settings(RESPA_MAILS_ENABLED=True)
@pytest.mark.django_db
def test_reservation_waiting_for_cash_comments_dont_trigger_notification(resource_with_manual_confirmation, api_client, user, unit_manager_api_client,
product_extra_manual_confirmation, reservation_waiting_for_payment_notification,
reservation_requested_notification, reservation_confirmed_notification,
customer_group):
"""Tests that commenting to reservation waiting for cash payment does not trigger new reservation confirmed notifications for client"""
resource_with_manual_confirmation.cash_payments_allowed = True
resource_with_manual_confirmation.save()
# client user makes a reservation with order which also requires manual confirmation
reservation_data = build_reservation_data(resource_with_manual_confirmation)
reservation_data['reserver_name'] = 'Nordea Demo'
reservation_data['reserver_email_address'] = '[email protected]'
reservation_data['billing_email_address'] = '[email protected]'
reservation_data['preferred_language'] = 'fi'
order_data = build_order_data(product_extra_manual_confirmation, customer_group=customer_group.id)
order_data['payment_method'] = Order.CASH
reservation_data['order'] = order_data

api_client.force_authenticate(user=user)
response = api_client.post(LIST_URL, data=reservation_data)
assert response.status_code == 201
assert response.data['state'] == Reservation.REQUESTED
assert len(mail.outbox) == 1
assert mail.outbox[0].subject == 'Reservation requested subject.'

# staff approves reservation
reservation_data['state'] = Reservation.CONFIRMED
mail.outbox = []
new_reservation = Reservation.objects.last()
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json')
assert response.status_code == 200
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT
assert len(mail.outbox) == 1
assert mail.outbox[0].subject == 'Reservation confirmed subject.'

# staff writes comments
reservation_data['comments'] = 'test comment'
reservation_data['state'] = Reservation.WAITING_FOR_CASH_PAYMENT
mail.outbox = []
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json')
assert response.status_code == 200
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT
assert len(mail.outbox) == 0

reservation_data['comments'] = 'other test comment'
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json')
assert response.status_code == 200
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT
assert len(mail.outbox) == 0


@pytest.mark.parametrize('data_state, reservation_state, is_manager, is_superuser, expected', [
('confirmed', 'waiting_for_cash_payment', False, False, 403),
('confirmed', 'waiting_for_cash_payment', True, False, 200),
('confirmed', 'waiting_for_cash_payment', False, True, 200),
('waiting_for_cash_payment', 'waiting_for_cash_payment', True, True, 400),
('denied', 'waiting_for_cash_payment', True, True, 400),
('confirmed', 'confirmed', True, False, 400),
('confirmed', 'requested', True, False, 400),
])
@pytest.mark.django_db
def test_confirm_cash_payment_in_the_past(api_client, user, staff_user, resource_with_manual_confirmation,
product_extra_manual_confirmation, customer_group, unit_manager_api_client,
data_state, reservation_state, is_manager, is_superuser, expected):
"""Tests that confirming cash payments works correctly for reservations in the past"""

resource_with_manual_confirmation.cash_payments_allowed = True
resource_with_manual_confirmation.save()
# client user makes a reservation with order which also requires manual confirmation
reservation_data = build_reservation_data(resource_with_manual_confirmation)
reservation_data['reserver_name'] = 'Nordea Demo'
reservation_data['reserver_email_address'] = '[email protected]'
reservation_data['billing_email_address'] = '[email protected]'
reservation_data['preferred_language'] = 'fi'
order_data = build_order_data(product_extra_manual_confirmation, customer_group=customer_group.id)
order_data['payment_method'] = Order.CASH
reservation_data['order'] = order_data

api_client.force_authenticate(user=user)
response = api_client.post(LIST_URL, data=reservation_data)
assert response.status_code == 201
assert response.data['state'] == Reservation.REQUESTED

# staff approves reservation
reservation_data['state'] = Reservation.CONFIRMED
new_reservation = Reservation.objects.last()
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json')
assert response.status_code == 200
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT

# set reservation to be in the past and test with given values
new_reservation = Reservation.objects.last()
new_reservation.begin = '2005-04-04T12:00:00+02:00'
new_reservation.end = '2005-04-04T13:00:00+02:00'
new_reservation.state = reservation_state
new_reservation.save()
new_reservation.refresh_from_db()
reservation_data['state'] = data_state
reservation_data['begin'] = '2005-04-04T12:00:00+02:00'
reservation_data['end'] = '2005-04-04T13:00:00+02:00'
if is_manager:
UnitAuthorization.objects.create(
subject=resource_with_manual_confirmation.unit, level=UnitAuthorizationLevel.manager, authorized=staff_user)
if is_superuser:
staff_user.is_superuser = True
staff_user.save()
api_client.force_authenticate(user=staff_user)
response = api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json')
assert response.status_code == expected
if expected == 400:
assert response.data['non_field_errors'][0] == 'Varauksen teko menneisyyteen ei ole sallittua'
if expected == 200:
assert response.data['state'] == Reservation.CONFIRMED
3 changes: 1 addition & 2 deletions qualitytool/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext as _
from django_jsonform.models.fields import ArrayField
from django.utils.functional import lazy
from solo.models import SingletonModel
from qualitytool.manager import qt_manager
from respa_admin.models import ChoiceArrayField
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ daemonize
database-sanitizer>=0.4.0
defusedxml
Delorean
Django==3.2.24
Django==3.2.25
django-admin-json-editor==0.2.3
django-allauth
django-anymail
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ deprecation==2.1.0
# via django-helusers-turku
dill==0.3.6
# via pylint
django==3.2.24
django==3.2.25
# via
# -r requirements.in
# django-admin-json-editor
Expand Down Expand Up @@ -196,7 +196,7 @@ djangorestframework==3.14.0
# drf-yasg
djangorestframework-simplejwt[crypto]==5.2.2
# via -r requirements.in
dnspython==2.3.0
dnspython==2.6.1
# via exchangelib
drf-oidc-auth==0.10.0
# via -r requirements.in
Expand Down Expand Up @@ -234,7 +234,7 @@ humanize==4.6.0
# delorean
icalendar==5.0.4
# via -r requirements.in
idna==3.4
idna==3.7
# via
# -r requirements.in
# requests
Expand All @@ -256,7 +256,7 @@ itypes==1.2.0
# via
# -r requirements.in
# coreapi
jinja2==3.1.3
jinja2==3.1.4
# via
# -r requirements.in
# coreschema
Expand Down Expand Up @@ -303,7 +303,7 @@ paramiko==3.4.0
# via -r requirements.in
phonenumbers==8.13.6
# via -r requirements.in
pillow==10.2.0
pillow==10.3.0
# via
# -r requirements.in
# easy-thumbnails
Expand Down Expand Up @@ -419,7 +419,7 @@ pyyaml==6.0
# swagger-spec-validator
raven==6.10.0
# via -r requirements.in
requests==2.31.0
requests==2.32.0
# via
# -r requirements.in
# coreapi
Expand Down Expand Up @@ -481,7 +481,7 @@ social-auth-core==4.3.0
# social-auth-app-django
soupsieve==2.4
# via beautifulsoup4
sqlparse==0.4.4
sqlparse==0.5.0
# via
# -r requirements.in
# django
Expand Down
Loading

0 comments on commit 22c2d93

Please sign in to comment.