Added columns to export function + additional order fixes

This commit is contained in:
Ed 2023-05-08 23:42:44 +02:00
parent 0c3e80320e
commit 37519f0b60
2 changed files with 13 additions and 4 deletions

View File

@ -8,12 +8,12 @@ bp = Blueprint("export", url_prefix="/manage/export")
@bp.route("/export.csv") @bp.route("/export.csv")
async def export_csv(request, order: Order): async def export_csv(request, order: Order):
if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!")
if order.code != 'HWUC9': raise exceptions.Forbidden("Birichino :)") if order.code not in ['HWUC9','9YKGJ']: raise exceptions.Forbidden("Birichino :)")
page = 0 page = 0
orders = {} orders = {}
ret = 'code;nome;cognome;nick;nazione;tessera;artista;fursuiter;sponsorship;early;late;shirt;roomsize;roommembers;payment;price\n' ret = 'status;code;nome;cognome;nick;nazione;tessera;artista;fursuiter;sponsorship;early;late;shirt;roomsize;roommembers;payment;price;refunds;staff\n'
while 1: while 1:
page += 1 page += 1
@ -24,11 +24,11 @@ async def export_csv(request, order: Order):
for r in r.json()['results']: for r in r.json()['results']:
o = Order(r) o = Order(r)
if o.status not in ['pending', 'paid']: continue
orders[o.code] = o orders[o.code] = o
ret += (';'.join(map(lambda x: str(x), ret += (';'.join(map(lambda x: str(x),
[ [
o.status,
o.code, o.code,
o.first_name, o.first_name,
o.last_name, o.last_name,
@ -44,7 +44,9 @@ async def export_csv(request, order: Order):
len(o.room_members), len(o.room_members),
','.join(o.room_members), ','.join(o.room_members),
o.payment_provider, o.payment_provider,
o.total-o.fees o.total-o.fees,
o.refunds,
o.ans('staff_role') or 'attendee',
]))) + "\n" ]))) + "\n"
return text(ret) return text(ret)

7
ext.py
View File

@ -25,6 +25,9 @@ class Order:
self.sponsorship = None self.sponsorship = None
self.has_early = False self.has_early = False
self.has_late = False self.has_late = False
self.first_name = None
self.last_name = None
self.country = None
for p in self.data['positions']: for p in self.data['positions']:
if p['item'] in [16, 38]: if p['item'] in [16, 38]:
@ -54,9 +57,13 @@ class Order:
self.total = float(data['total']) self.total = float(data['total'])
self.fees = 0 self.fees = 0
self.refunds = 0
for fee in data['fees']: for fee in data['fees']:
self.fees += float(fee['value']) self.fees += float(fee['value'])
for ref in data['refunds']:
self.refunds += float(ref['amount'])
answers = ['payment_provider', 'shirt_size', 'birth_date', 'fursona_name', 'room_confirmed', 'room_id'] answers = ['payment_provider', 'shirt_size', 'birth_date', 'fursona_name', 'room_confirmed', 'room_id']
self.payment_provider = data['payment_provider'] self.payment_provider = data['payment_provider']