Just some stuff

This commit is contained in:
shamoon
2024-12-20 22:13:53 -08:00
parent 112b39c4de
commit 198ee6ea09
4 changed files with 33 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
from pathlib import Path
from django.conf import settings
from drafthorse.models.document import Document
from drafthorse.models.document import Document as InvoiceDocument
from gotenberg_client import GotenbergClient
from gotenberg_client.options import MarginType
from gotenberg_client.options import MarginUnitType
@@ -22,6 +22,10 @@ class EInvoiceDocumentParser(TikaDocumentParser):
"""
logging_name = "paperless.parsing.einvoice"
template_loader = FileSystemLoader(
searchpath=Path(__file__).parent / "templates",
)
template_env = Environment(loader=template_loader)
def convert_to_pdf(self, document_path: Path, file_name):
pdf_path = Path(self.tempdir) / "convert.pdf"
@@ -29,15 +33,25 @@ class EInvoiceDocumentParser(TikaDocumentParser):
with document_path.open("r") as f:
xml = f.read().encode("utf-8")
invoice = Document.parse(xml)
invoice = InvoiceDocument.parse(xml)
context = {
"id": invoice.trade.agreement.seller.name,
"id": invoice.header.id,
"seller_name": invoice.trade.agreement.seller.name,
"seller_address": invoice.trade.agreement.seller.address,
"buyer_name": invoice.trade.agreement.buyer.name,
"buyer_address": invoice.trade.agreement.buyer.address,
"issue_date": invoice.header.issue_date_time,
"items": [
{
"name": item.product.name,
"description": item.product.description,
# "quantity": item.product.quantity,
"subtotal": item.settlement.monetary_summation.total_amount,
}
for item in invoice.trade.items.children # TODO: Fix this
],
}
templateLoader = FileSystemLoader(
searchpath=Path(__file__).parent / "templates",
)
templateEnv = Environment(loader=templateLoader)
template = templateEnv.get_template("invoice.j2.html")
template = self.template_env.get_template("invoice.j2.html")
html_file = Path(self.tempdir) / "invoice_as_html.html"
html_file.write_text(
template.render(context),

View File

@@ -10,10 +10,10 @@
<h1>Rechnung</h1>
<p id="fromaddress">
<u>westnetz w.V., Karl-Heine-Str. 93, 04229 Leipzig</u>
<u>{{ seller_name }}: {{ seller_address }}</u>
</p>
<p id="toaddress">
{{ address | join("<br />") }}
{{ buyer_name }}: {{ buyer_address }}
</p>
@@ -25,8 +25,7 @@
</tr>
<tr>
<td class="info">{{ id }}</td>
<td class="info">{{ period }}</td>
<td class="info">{{ date }}</td>
<td class="info">{{ issue_date }}</td>
</tr>
</table>
@@ -36,16 +35,12 @@
<tr>
<th id="tablepos">Pos.</th>
<th id="tabledesc">Beschreibung</th>
<th id="tablesingle">Einzelpreis</th>
<th id="tablequantity">Anzahl</th>
<th id="tabletotal">Gesamtpreis</th>
</tr>
{% for item in items %}
<tr class="position">
<td class="positions">{{ item.item }}</td>
<td class="positions">{{ item.name }}</td>
<td class="positions">{{ item.description }}</td>
<td class="positions">{{ item.price }}</td>
<td class="positions">{{ item.quantity }}</td>
<td class="positions">{{ item.subtotal }}</td>
</tr>
{% endfor %}
@@ -74,7 +69,5 @@
Diese Rechnung wurde maschinell erstellt und ist auch ohne Unterschrift gültig.
</p>
<embed src="file:///{{ logo_asset_file }}" id="logo" />
</body>
</html>