Skip to content

Commit

Permalink
Merge pull request #309 from City-of-Turku/hotfix/cash-payment-expira…
Browse files Browse the repository at this point in the history
…tion

Hotfixed staff made cash payments expiring
  • Loading branch information
SanttuA authored Jan 3, 2024
2 parents 8ed8678 + 72ebd1b commit b02f7c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,11 @@ def can_view(self, user):
def update_expired(self) -> int:
earliest_allowed_timestamp = now() - timedelta(minutes=settings.RESPA_PAYMENTS_PAYMENT_WAITING_TIME)
log_entry_timestamps = OrderLogEntry.objects.filter(order=OuterRef('pk')).order_by('id').values('timestamp')
# Expire only online payments. Cash payments should not expire.
too_old_waiting_orders = self.filter(
state=Order.WAITING,
is_requested_order=False
is_requested_order=False,
payment_method=Order.ONLINE
).annotate(
created_at=Subquery(
log_entry_timestamps[:1]
Expand Down
17 changes: 17 additions & 0 deletions payments/tests/test_expire_too_old_unpaid_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,20 @@ def test_other_than_waiting_order_wont_get_expired(two_hour_reservation, order_s
order.refresh_from_db()
assert two_hour_reservation.state == reservation_state
assert order.state == order_state


@pytest.mark.parametrize('is_requested_order', (True, False))
def test_waiting_for_cash_payment_reservations_dont_get_expired(order_with_products, is_requested_order):
"""Tests that reservations that are waiting for cash payment dont get expired"""
order_with_products.is_requested_order = is_requested_order
order_with_products.payment_method = Order.CASH
order_with_products.reservation.state = Reservation.WAITING_FOR_CASH_PAYMENT
set_order_last_modified_at(order_with_products, get_order_expired_time())
order_with_products.save()
order_with_products.reservation.save()

management.call_command(COMMAND_NAME)

order_with_products.refresh_from_db()
assert order_with_products.state == Order.WAITING
assert order_with_products.reservation.state == Reservation.WAITING_FOR_CASH_PAYMENT
2 changes: 1 addition & 1 deletion respa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = 'tku-v1.9'
__version__ = 'tku-v1.9.1'

VERSION = __version__

0 comments on commit b02f7c4

Please sign in to comment.