Fixed crash when loading a canceled order

This commit is contained in:
Ed 2023-02-02 22:47:06 +01:00
parent 5d00cdd7f4
commit e67fd8ea1f
2 changed files with 9 additions and 4 deletions

View File

@ -22,9 +22,9 @@ async def export_csv(request, order: Order):
if r.status_code == 404: break
for r in r.json()['results']:
if r['status'] not in ['n', 'p']: continue
o = Order(r)
if o.status not in ['pending', 'paid']: continue
orders[o.code] = o
ret += (';'.join(map(lambda x: str(x),

11
ext.py
View File

@ -14,6 +14,10 @@ class Order:
self.time = time()
self.data = data
self.status = {'n': 'pending', 'p': 'paid', 'e': 'expired', 'c': 'canceled'}[self.data['status']]
if not len(self.data['positions']):
self.status = 'canceled'
self.code = data['code']
self.pending_update = False
@ -181,7 +185,8 @@ class OrderManager:
data = res.json()
for o in data['results']:
if o['status'] in ['c', 'e']: continue
o = Order(o)
if o.status in ['canceled', 'expired']: continue
self.add_cache(Order(o))
# If a cached order is needed, just get it if available
@ -207,11 +212,11 @@ class OrderManager:
res = res.json()
if res['status'] in ['c', 'e']:
order = Order(res)
if order.status in ['canceled', 'expired']:
if request:
raise exceptions.Forbidden(f"Your order has been deleted. Contact support with your order identifier ({res['code']}) for further info.")
order = Order(res)
self.add_cache(order)
if request and secret != res['secret']: