Startet på fakturageneratoren
This commit is contained in:
parent
ffeb651716
commit
de96006cdb
55
otime.py
55
otime.py
@ -92,10 +92,17 @@ class Event:
|
|||||||
for c in self.courses:
|
for c in self.courses:
|
||||||
if oc.course_str == c.name:
|
if oc.course_str == c.name:
|
||||||
oc.course = c
|
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):
|
def match_all(self):
|
||||||
self.match_runners_cards()
|
self.match_runners_cards()
|
||||||
self.match_runners_o_classes()
|
self.match_runners_o_classes()
|
||||||
self.match_o_classes_courses()
|
self.match_o_classes_courses()
|
||||||
|
self.match_runners_fees()
|
||||||
|
|
||||||
def get_xml_res(self):
|
def get_xml_res(self):
|
||||||
root = ET.Element('ResultList')
|
root = ET.Element('ResultList')
|
||||||
@ -247,13 +254,13 @@ class Event:
|
|||||||
def create_start_list_pdf(self, file_name):
|
def create_start_list_pdf(self, file_name):
|
||||||
pdf = FPDF()
|
pdf = FPDF()
|
||||||
pdf.add_page()
|
pdf.add_page()
|
||||||
pdf.add_font("DejaVuSans", fname="/usr/share/fonts/truetype/DejaVuSans.ttf")
|
pdf.add_font("LiberationSans", fname="data/fonts/LiberationSans-Regular.ttf")
|
||||||
pdf.set_font("DejaVuSans", size=10)
|
pdf.set_font("LiberationSans", size=10)
|
||||||
line_height = pdf.font_size * 2
|
line_height = pdf.font_size * 2
|
||||||
col_width = pdf.epw / 4 # distribute content evenly
|
col_width = pdf.epw / 4 # distribute content evenly
|
||||||
for runner in self.runners:
|
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.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)
|
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:
|
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)
|
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.ln(line_height)
|
||||||
pdf.output(file_name)
|
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.
|
# The runner object stores all the data specific to a runner.
|
||||||
class Runner:
|
class Runner:
|
||||||
def __init__(self, runner_id, first, last, **kwargs):
|
def __init__(self, runner_id, first, last, **kwargs):
|
||||||
@ -309,12 +337,13 @@ class Runner:
|
|||||||
self.start_time = None
|
self.start_time = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.fee_str = kwargs['fee_str']
|
self.fee_id = kwargs['fee_id']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.fee_str = None
|
self.fee_id = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.fee = kwargs['fee']
|
self.fee = kwargs['fee']
|
||||||
|
self.fee_id = kwargs['fee'].id
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.fee = None
|
self.fee = None
|
||||||
|
|
||||||
@ -389,9 +418,13 @@ class Runner:
|
|||||||
elif self.check_codes() == False:
|
elif self.check_codes() == False:
|
||||||
return 'Disqualified'
|
return 'Disqualified'
|
||||||
|
|
||||||
|
# TODO: må forbedres
|
||||||
def rank(self, allrunners):
|
def rank(self, allrunners):
|
||||||
c_ranked = rank_runners(allrunners, self.o_class)
|
c_ranked = rank_runners(allrunners, self.o_class)
|
||||||
|
try:
|
||||||
return c_ranked.index(self) + 1
|
return c_ranked.index(self) + 1
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
def res_codes(self):
|
def res_codes(self):
|
||||||
if self.o_class.course.forked == False:
|
if self.o_class.course.forked == False:
|
||||||
@ -441,7 +474,8 @@ class Runner:
|
|||||||
'card': self.card,
|
'card': self.card,
|
||||||
'o_class_str': self.o_class_str,
|
'o_class_str': self.o_class_str,
|
||||||
'fork' : self.fork,
|
'fork' : self.fork,
|
||||||
'start_time': self.start_time
|
'start_time': self.start_time,
|
||||||
|
'fee_id': self.fee_id
|
||||||
}
|
}
|
||||||
|
|
||||||
class CardDump:
|
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
|
last = name.find('./{http://www.orienteering.org/datastandard/3.0}Family').text
|
||||||
|
|
||||||
organisation = p_entry.find('./{http://www.orienteering.org/datastandard/3.0}Organisation')
|
organisation = p_entry.find('./{http://www.orienteering.org/datastandard/3.0}Organisation')
|
||||||
|
if organisation is not None:
|
||||||
club_id = organisation.find('./{http://www.orienteering.org/datastandard/3.0}Id').text
|
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 = 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
|
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']
|
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_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
|
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:
|
try:
|
||||||
card = int(p_entry.find('./{http://www.orienteering.org/datastandard/3.0}ControlCard').text)
|
card = int(p_entry.find('./{http://www.orienteering.org/datastandard/3.0}ControlCard').text)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -681,7 +720,7 @@ def runners_from_xml_entries(xml_file):
|
|||||||
start_time = None
|
start_time = None
|
||||||
runners.append(Runner(rid, first, last, club=club_name, club_id=club_id,
|
runners.append(Runner(rid, first, last, club=club_name, club_id=club_id,
|
||||||
country=country,card=card, o_class_str=class_str,
|
country=country,card=card, o_class_str=class_str,
|
||||||
start_time=start_time))
|
start_time=start_time, fee_id=fee_id))
|
||||||
return runners
|
return runners
|
||||||
|
|
||||||
def fees_from_xml_entries(xml_file):
|
def fees_from_xml_entries(xml_file):
|
||||||
@ -692,7 +731,7 @@ def fees_from_xml_entries(xml_file):
|
|||||||
added_ids = []
|
added_ids = []
|
||||||
fee_objs = []
|
fee_objs = []
|
||||||
for fee in allfees:
|
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:
|
if f_id not in added_ids:
|
||||||
added_ids.append(f_id)
|
added_ids.append(f_id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user