Better handling of canceled orders

If an order is canceled with a paid fee pretix still returns that it's paid
This commit is contained in:
Stranck 2024-05-13 10:25:45 +02:00
parent 938bc68383
commit 383b5bbede
3 changed files with 19 additions and 13 deletions

2
app.py
View File

@ -55,7 +55,7 @@ async def handleException(request, exception):
traceback.print_exc() traceback.print_exc()
if statusCode == 403: if statusCode == 403:
clear_session(r) await clear_session(r)
return r return r

View File

@ -80,16 +80,17 @@ async def send_unconfirm_message(room_order, orders):
issues_html += "</ul>" issues_html += "</ul>"
for member in orders: for member in orders:
plain_body = EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['plain'].format(member.name, room_order.room_name, issues_plain) if(member.status != 'canceled'):
html_body = render_email_template(EMAILS_TEXT["ROOM_UNCONFIRM_TITLE"], EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['html'].format(member.name, room_order.room_name, issues_html)) plain_body = EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['plain'].format(member.name, room_order.room_name, issues_plain)
plain_text = MIMEText(plain_body, "plain") html_body = render_email_template(EMAILS_TEXT["ROOM_UNCONFIRM_TITLE"], EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['html'].format(member.name, room_order.room_name, issues_html))
html_text = MIMEText(html_body, "html") plain_text = MIMEText(plain_body, "plain")
message = MIMEMultipart("alternative") html_text = MIMEText(html_body, "html")
message.attach(plain_text) message = MIMEMultipart("alternative")
message.attach(html_text) message.attach(plain_text)
message['Subject'] = f'[{EMAIL_SENDER_NAME}] Your room cannot be confirmed' message.attach(html_text)
message['To'] = f"{member.name} <{member.email}>" message['Subject'] = f'[{EMAIL_SENDER_NAME}] Your room cannot be confirmed'
memberMessages.append(message) message['To'] = f"{member.name} <{member.email}>"
memberMessages.append(message)
if len(memberMessages) == 0: return if len(memberMessages) == 0: return

7
ext.py
View File

@ -20,6 +20,10 @@ class Order:
self.time = time() self.time = time()
self.data = data self.data = data
if(len(self.data['positions']) == 0):
for fee in data['fees']:
if(fee['fee_type'] == "cancellation"):
self.data['status'] = 'c'
self.status = {'n': 'pending', 'p': 'paid', 'e': 'expired', 'c': 'canceled'}[self.data['status']] self.status = {'n': 'pending', 'p': 'paid', 'e': 'expired', 'c': 'canceled'}[self.data['status']]
self.secret = data['secret'] self.secret = data['secret']
@ -219,7 +223,8 @@ class Order:
# del self.answers[i]['options'] # del self.answers[i]['options']
# del self.answers[i]['option_identifiers'] # del self.answers[i]['option_identifiers']
res = await pretixClient.patch(f'orderpositions/{self.position_id}/', json={'answers': self.answers}, expectedStatusCodes=None) ans = [] if self.status == "canceled" else self.answers
res = await pretixClient.patch(f'orderpositions/{self.position_id}/', json={'answers': ans}, expectedStatusCodes=None)
if res.status_code != 200: if res.status_code != 200:
e = res.json() e = res.json()