From de96006cdbee86232e5bf8b8cc7004e88433d352 Mon Sep 17 00:00:00 2001 From: Trygve Date: Wed, 1 Jun 2022 17:42:55 +0200 Subject: [PATCH] =?UTF-8?q?Startet=20p=C3=A5=20fakturageneratoren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime.py | 65 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/otime.py b/otime.py index 644acdd..d88fc28 100644 --- a/otime.py +++ b/otime.py @@ -92,10 +92,17 @@ class Event: for c in self.courses: if oc.course_str == c.name: oc.course = c + + def match_runners_fees(self): + for r in self.runners: + for f in self.fees: + if r.fee_id == f.id: + r.fee = f def match_all(self): self.match_runners_cards() self.match_runners_o_classes() self.match_o_classes_courses() + self.match_runners_fees() def get_xml_res(self): root = ET.Element('ResultList') @@ -247,13 +254,13 @@ class Event: def create_start_list_pdf(self, file_name): pdf = FPDF() pdf.add_page() - pdf.add_font("DejaVuSans", fname="/usr/share/fonts/truetype/DejaVuSans.ttf") - pdf.set_font("DejaVuSans", size=10) + pdf.add_font("LiberationSans", fname="data/fonts/LiberationSans-Regular.ttf") + pdf.set_font("LiberationSans", size=10) line_height = pdf.font_size * 2 col_width = pdf.epw / 4 # distribute content evenly for runner in self.runners: pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L') - pdf.multi_cell(col_width, line_height, runner.o_class.name, border=1, ln=3, max_line_height=pdf.font_size) + pdf.multi_cell(col_width, line_height, runner.o_class_str, border=1, ln=3, max_line_height=pdf.font_size) pdf.multi_cell(col_width, line_height, str(runner.card), border=1, ln=3, max_line_height=pdf.font_size) if runner.start_time != None: pdf.multi_cell(col_width, line_height, str(runner.start_time), border=1, ln=3, max_line_height=pdf.font_size) @@ -262,6 +269,27 @@ class Event: pdf.ln(line_height) pdf.output(file_name) + def create_invoices(self, file_name): + pdf = FPDF() + pdf.add_page() + pdf.add_font("LiberationSans", fname="data/fonts/LiberationSans-Regular.ttf") + pdf.set_font("LiberationSans", size=10) + line_height = pdf.font_size * 2 + col_width = pdf.epw / 7 # distribute content evenly + for runner in self.runners: + pdf.multi_cell(col_width, line_height, runner.id, border=1, ln=3,max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, runner.last, border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, runner.first, border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, runner.o_class_str, border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, str(runner.card), border=1, ln=3, max_line_height=pdf.font_size) + if runner.start_time != None: + pdf.multi_cell(col_width, line_height, str(runner.start_time), border=1, ln=3, max_line_height=pdf.font_size) + else: + pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size) + pdf.multi_cell(col_width, line_height, str(runner.rank(self.runners)), border=1, ln=3, max_line_height=pdf.font_size) + pdf.ln(line_height) + pdf.output(file_name) + # The runner object stores all the data specific to a runner. class Runner: def __init__(self, runner_id, first, last, **kwargs): @@ -309,12 +337,13 @@ class Runner: self.start_time = None try: - self.fee_str = kwargs['fee_str'] + self.fee_id = kwargs['fee_id'] except KeyError: - self.fee_str = None + self.fee_id = None try: self.fee = kwargs['fee'] + self.fee_id = kwargs['fee'].id except KeyError: self.fee = None @@ -389,9 +418,13 @@ class Runner: elif self.check_codes() == False: return 'Disqualified' + # TODO: må forbedres def rank(self, allrunners): c_ranked = rank_runners(allrunners, self.o_class) - return c_ranked.index(self) + 1 + try: + return c_ranked.index(self) + 1 + except ValueError: + return None def res_codes(self): if self.o_class.course.forked == False: @@ -441,7 +474,8 @@ class Runner: 'card': self.card, 'o_class_str': self.o_class_str, 'fork' : self.fork, - 'start_time': self.start_time + 'start_time': self.start_time, + 'fee_id': self.fee_id } class CardDump: @@ -665,14 +699,19 @@ def runners_from_xml_entries(xml_file): last = name.find('./{http://www.orienteering.org/datastandard/3.0}Family').text organisation = p_entry.find('./{http://www.orienteering.org/datastandard/3.0}Organisation') - club_id = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Id').text - club_name = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Name').text - club_name_short = organisation.find('./{http://www.orienteering.org/datastandard/3.0}ShortName').text - country = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Country').attrib['code'] + if organisation is not None: + club_id = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Id').text + club_name = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Name').text + club_name_short = organisation.find('./{http://www.orienteering.org/datastandard/3.0}ShortName').text + country = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Country').attrib['code'] + else: + club_id = club_name = club_name_short = country = None class_el = p_entry.find('./{http://www.orienteering.org/datastandard/3.0}Class') class_str = class_el.find('./{http://www.orienteering.org/datastandard/3.0}Name').text + fee_id = int(p_entry.find('./{http://www.orienteering.org/datastandard/3.0}AssignedFee/{http://www.orienteering.org/datastandard/3.0}Fee/{http://www.orienteering.org/datastandard/3.0}Id').text) + try: card = int(p_entry.find('./{http://www.orienteering.org/datastandard/3.0}ControlCard').text) except AttributeError: @@ -681,7 +720,7 @@ def runners_from_xml_entries(xml_file): start_time = None runners.append(Runner(rid, first, last, club=club_name, club_id=club_id, country=country,card=card, o_class_str=class_str, - start_time=start_time)) + start_time=start_time, fee_id=fee_id)) return runners def fees_from_xml_entries(xml_file): @@ -692,7 +731,7 @@ def fees_from_xml_entries(xml_file): added_ids = [] fee_objs = [] for fee in allfees: - f_id = fee.find('./{http://www.orienteering.org/datastandard/3.0}Id').text + f_id = int(fee.find('./{http://www.orienteering.org/datastandard/3.0}Id').text) if f_id not in added_ids: added_ids.append(f_id)