From ac58eb5a24f1eea4cf81c35d99ed5d5266a94bc0 Mon Sep 17 00:00:00 2001 From: SanttuA Date: Wed, 3 Jan 2024 07:39:51 +0200 Subject: [PATCH] Fixed staff made cash payments expiring Previously when staff made a reservation with cash payment, their reservation would expire due to it being handled differently from normal client cash handling. This fix addresses the issue by excluding cash payments from normal payment expiration handling. --- payments/models.py | 4 +++- .../tests/test_expire_too_old_unpaid_orders.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/payments/models.py b/payments/models.py index 8958715cd..b62959c10 100644 --- a/payments/models.py +++ b/payments/models.py @@ -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] diff --git a/payments/tests/test_expire_too_old_unpaid_orders.py b/payments/tests/test_expire_too_old_unpaid_orders.py index 6ea46d1e8..dce88e206 100644 --- a/payments/tests/test_expire_too_old_unpaid_orders.py +++ b/payments/tests/test_expire_too_old_unpaid_orders.py @@ -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