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 diff --git a/respa/__init__.py b/respa/__init__.py index a694ba247..b41cc61f8 100644 --- a/respa/__init__.py +++ b/respa/__init__.py @@ -1,3 +1,3 @@ -__version__ = 'tku-v1.9' +__version__ = 'tku-v1.9.1' VERSION = __version__