Skip to content

Commit

Permalink
Fixed staff made cash payments expiring
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SanttuA committed Jan 3, 2024
1 parent 8ed8678 commit ac58eb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit ac58eb5

Please sign in to comment.