refactor bill pdf code

This commit is contained in:
Gregory Trullemans 2022-09-20 14:16:37 +02:00
parent b7b5635e18
commit 0ea90b704c
1 changed files with 7 additions and 9 deletions

View File

@ -504,7 +504,6 @@ class BillPaper(PDFDocument):
self.style = self.styles["BodyText"]
self.add_header(contract)
self.y = Y - 125
self.add_bill_title(contract)
self.add_prestations(contract)
self.add_conclusion(contract)
@ -520,20 +519,20 @@ class BillPaper(PDFDocument):
Returns:
ne retourne rien
"""
self.y = 650
text = (("<b>" + contract.client.name + "</b>") if contract.client.is_company else "") + "<br />" + "A l'attention de <b>" + contract.client.contact + "</b><br />" + contract.client.address + "<br />" + str(contract.client.postal_code) + " " + contract.client.city + "<br /><br />Concernant la/le <b>" + contract.title + "</b>"
paragraph = Paragraph(text, self.style)
width, height = paragraph.wrap(10*cm, 10*cm)
paragraph.drawOn(self.document, TITLED_X, self.y - height)
self.add_vspace(-height * 1.25)
paragraph.drawOn(self.document, TITLED_X, self.y)
self.add_vspace(BIG_LINE_HEIGHT)
def __add_section_title(self, title_text):
""" Ajout le titre d'une section """
text = "<b>" + title_text + "</b>"
paragraph = Paragraph(text, self.style)
width, height = paragraph.wrap(8*cm, self.y)
paragraph.drawOn(self.document, INDENTED_X, self.y - height)
width, height = paragraph.wrap(8*cm, 8*cm)
paragraph.drawOn(self.document, INDENTED_X, self.y)
self.add_vspace(-height)
def add_prestations(self, contract):
@ -580,8 +579,8 @@ class BillPaper(PDFDocument):
)
table = Table(data, [2.6*cm, 8.2*cm, 2.6*cm, 2.6*cm, 2.6*cm])
table.setStyle(style)
width, height = table.wrapOn(self.document, X, self.y)
self.add_vspace(-height - 5)
width, height = table.wrapOn(self.document, 19*cm, 15*cm)
self.add_vspace(-(9 * height / 10))
table.drawOn(self.document, X, self.y)
self.add_vspace(-height / 3)
@ -653,7 +652,6 @@ class BillPaper(PDFDocument):
""" Ajoute les conditions générales de payement au bas de la facture """
self.y = 125
self.__add_section_title("Conditions générales de paiement")
self.add_vspace()
lines = [
"Facture payable au comptant.",