Fixed problems with canceled orders

This commit is contained in:
Luca Sorace "Stranck 2024-03-12 21:35:52 +01:00
parent c405a49366
commit f4ebc83a9b
2 changed files with 21 additions and 9 deletions

12
ext.py
View File

@ -35,16 +35,21 @@ 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.first_name = "None"
self.last_name = None self.last_name = "None"
self.country = 'xx' self.country = 'xx'
self.address = None self.address = None
self.checked_in = False self.checked_in = False
self.room_type = None self.room_type = None
self.daily = False self.daily = False
self.dailyDays = [] self.dailyDays = []
self.bed_in_room = -1
self.room_person_no = 0 self.room_person_no = 0
self.answers = [] self.answers = []
self.position_id = -1
self.position_positionid = -1
self.position_positiontypeid = -1
self.barcode = "None"
idata = data['invoice_address'] idata = data['invoice_address']
if idata: if idata:
@ -106,6 +111,9 @@ class Order:
self.phone = data['phone'] self.phone = data['phone']
self.room_errors = [] self.room_errors = []
self.loadAns() self.loadAns()
if(self.bed_in_room < 0):
self.status = "canceled" # Must refer to the previous status assignment
def loadAns(self): def loadAns(self):
self.shirt_size = self.ans('shirt_size') self.shirt_size = self.ans('shirt_size')
self.is_artist = True if self.ans('is_artist') != 'No' else False self.is_artist = True if self.ans('is_artist') != 'No' else False

View File

@ -1,6 +1,7 @@
from sanic.log import logger, logging from sanic.log import logger, logging
from logging import LogRecord from logging import LogRecord
from config import * from config import *
import traceback
METRICS_REQ_NO = 0 METRICS_REQ_NO = 0
METRICS_ERR_NO = 0 # Errors served to the clients METRICS_ERR_NO = 0 # Errors served to the clients
@ -47,7 +48,7 @@ def getMetricsText():
def getRoomCountersText(request): def getRoomCountersText(request):
out = [] out = []
try : try:
daily = 0 daily = 0
counters = {} counters = {}
counters_early = {} counters_early = {}
@ -61,11 +62,13 @@ def getRoomCountersText(request):
if(order.daily): if(order.daily):
daily += 1 daily += 1
else: else:
counters[order.bed_in_room] += 1 # Order.status must reflect the one in the Order() constructor inside ext.py
if(order.has_early): if(order.status in ["pending", "paid"] and hasattr(order, "bed_in_room") and order.bed_in_room in counters):
counters_early[order.bed_in_room] += 1 counters[order.bed_in_room] += 1
if(order.has_late): if(order.has_early):
counters_late[order.bed_in_room] += 1 counters_early[order.bed_in_room] += 1
if(order.has_late):
counters_late[order.bed_in_room] += 1
for id, count in counters.items(): for id, count in counters.items():
out.append(f'webint_order_room_counter{{days="normal", label="{ROOM_TYPE_NAMES[id]}"}} {count}') out.append(f'webint_order_room_counter{{days="normal", label="{ROOM_TYPE_NAMES[id]}"}} {count}')
@ -76,7 +79,8 @@ def getRoomCountersText(request):
out.append(f'webint_order_room_counter{{label="Daily"}} {daily}') out.append(f'webint_order_room_counter{{label="Daily"}} {daily}')
except Exception as e: except Exception as e:
print(e) print(traceback.format_exc())
logger.warning("Error in loading metrics rooms") logger.warning("Error in loading metrics rooms")
return "\n".join(out) return "\n".join(out)