Just some stuff

This commit is contained in:
shamoon 2024-12-20 22:13:53 -08:00
parent 112b39c4de
commit 198ee6ea09
No known key found for this signature in database
4 changed files with 33 additions and 19 deletions

View File

@ -198,6 +198,12 @@ Docker, this may be the `environment` key of the webserver or a
containing the configuration parameters. Be sure to use the correct format containing the configuration parameters. Be sure to use the correct format
and watch out for indentation if editing the YAML file. and watch out for indentation if editing the YAML file.
#### [`PAPERLESS_EINVOICE_PARSER_ENABLED=<bool>`](#PAPERLESS_EINVOICE_PARSER_ENABLED) {#PAPERLESS_EINVOICE_PARSER_ENABLED}
: Enable (or disable) the e-invoice parser. Note that this feature requires Tika to be enabled.
Defaults to false.
## Paths and folders ## Paths and folders
#### [`PAPERLESS_CONSUMPTION_DIR=<path>`](#PAPERLESS_CONSUMPTION_DIR) {#PAPERLESS_CONSUMPTION_DIR} #### [`PAPERLESS_CONSUMPTION_DIR=<path>`](#PAPERLESS_CONSUMPTION_DIR) {#PAPERLESS_CONSUMPTION_DIR}

View File

@ -87,6 +87,7 @@
#PAPERLESS_TIKA_ENABLED=false #PAPERLESS_TIKA_ENABLED=false
#PAPERLESS_TIKA_ENDPOINT=http://localhost:9998 #PAPERLESS_TIKA_ENDPOINT=http://localhost:9998
#PAPERLESS_TIKA_GOTENBERG_ENDPOINT=http://localhost:3000 #PAPERLESS_TIKA_GOTENBERG_ENDPOINT=http://localhost:3000
#PAPERLESS_EINVOICE_PARSER_ENABLED=true
# Binaries # Binaries

View File

@ -1,7 +1,7 @@
from pathlib import Path from pathlib import Path
from django.conf import settings 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 import GotenbergClient
from gotenberg_client.options import MarginType from gotenberg_client.options import MarginType
from gotenberg_client.options import MarginUnitType from gotenberg_client.options import MarginUnitType
@ -22,6 +22,10 @@ class EInvoiceDocumentParser(TikaDocumentParser):
""" """
logging_name = "paperless.parsing.einvoice" 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): def convert_to_pdf(self, document_path: Path, file_name):
pdf_path = Path(self.tempdir) / "convert.pdf" pdf_path = Path(self.tempdir) / "convert.pdf"
@ -29,15 +33,25 @@ class EInvoiceDocumentParser(TikaDocumentParser):
with document_path.open("r") as f: with document_path.open("r") as f:
xml = f.read().encode("utf-8") xml = f.read().encode("utf-8")
invoice = Document.parse(xml) invoice = InvoiceDocument.parse(xml)
context = { 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( template = self.template_env.get_template("invoice.j2.html")
searchpath=Path(__file__).parent / "templates",
)
templateEnv = Environment(loader=templateLoader)
template = templateEnv.get_template("invoice.j2.html")
html_file = Path(self.tempdir) / "invoice_as_html.html" html_file = Path(self.tempdir) / "invoice_as_html.html"
html_file.write_text( html_file.write_text(
template.render(context), template.render(context),

View File

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