Compare commits
2 Commits
b8bd3f288b
...
dd74245c64
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd74245c64 | ||
|
|
b669e065f5 |
@@ -13,6 +13,7 @@ class HtmlTemplate:
|
||||
if not Path(templates).exists():
|
||||
raise FileNotFoundError(f'Inivalid path to template files: {templates}')
|
||||
self.templates = templates
|
||||
self.path_to_template = Path(templates)
|
||||
|
||||
def prepare_template(self, invoice_data, envelope_data):
|
||||
try:
|
||||
@@ -53,15 +54,14 @@ class HtmlTemplate:
|
||||
html_content = markdown.markdown(md_content)
|
||||
return html_content
|
||||
|
||||
@staticmethod
|
||||
def convert_html_to_pdf(source_html, output_filename):
|
||||
def convert_html_to_pdf(self, source_html, output_filename):
|
||||
# open output file for writing (truncated binary)
|
||||
result_file = open(output_filename, "w+b")
|
||||
|
||||
# convert HTML to PDF
|
||||
pisa_status = pisa.CreatePDF(
|
||||
source_html, # the HTML to convert
|
||||
path='test_data/templates/fonts',
|
||||
path=str(self.path_to_template / 'fonts'),
|
||||
dest=result_file
|
||||
) # file handle to recieve result
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ def main():
|
||||
print('Generating invoice...')
|
||||
invoice_pdf = Path(invoice_data.Id).with_suffix('.pdf')
|
||||
print(f'Invoice PDF: {invoice_pdf}')
|
||||
html_generator.HtmlTemplate.convert_html_to_pdf(template, invoice_pdf)
|
||||
generator.convert_html_to_pdf(template, invoice_pdf)
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
return
|
||||
|
||||
@@ -9,7 +9,6 @@ Positions:
|
||||
Quantity: 100
|
||||
|
||||
- Title: "Aschlecken"
|
||||
SubTitle: "Leistungszeitraum: 11/2022"
|
||||
PricePerUnit: 99.99
|
||||
Quantity: 12
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@
|
||||
}
|
||||
|
||||
.positionen {
|
||||
padding-top: 1mm;
|
||||
padding-bottom: 1mm;
|
||||
padding-top: 1pt;
|
||||
padding-bottom: 1pt;
|
||||
}
|
||||
|
||||
.links {
|
||||
@@ -134,6 +134,14 @@
|
||||
margin-left: -.55cm;
|
||||
}
|
||||
|
||||
.position_top {
|
||||
padding-top: 1pt;
|
||||
}
|
||||
|
||||
.position_bottom {
|
||||
padding-bottom: 1pt;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -180,15 +188,18 @@
|
||||
<th class="rechts" style="width: 15%">Betrag</th>
|
||||
</tr>
|
||||
{% for position in invoice.Positions %}
|
||||
<tr class="positionen">
|
||||
<td class="links">{{ position.Title }}<br><span class="small">{{ position.SubTitle }}</span></td>
|
||||
<td class="rechts">{{ format_float(position.Quantity | float) }}</td>
|
||||
<td class="rechts">{{ format_float((position.PricePerUnit or invoice.PricePerUnit) | float) }}
|
||||
<tr>
|
||||
<td class="links position_top">{{ position.Title }}</td>
|
||||
<td class="rechts" rowspan="2">{{ format_float(position.Quantity | float) }}</td>
|
||||
<td class="rechts" rowspan="2">{{ format_float((position.PricePerUnit or invoice.PricePerUnit) | float) }}
|
||||
</td>
|
||||
<td class="rechts">{{ format_float(position.Quantity * ( position.PricePerUnit or
|
||||
<td class="rechts" rowspan="2">{{ format_float(position.Quantity * ( position.PricePerUnit or
|
||||
invoice.PricePerUnit ))}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="links small position_bottom">{{ position.SubTitle }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="summe">
|
||||
<td></td>
|
||||
|
||||
Reference in New Issue
Block a user