From 2ffa7d49c08a46e3bdefa865a993641878d72938 Mon Sep 17 00:00:00 2001
From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com>
Date: Fri, 10 Jan 2025 21:17:45 +0100
Subject: [PATCH] feat: provide logos via jinja method (#59) (#61)
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
---
README.md | 16 ++++++++++++++++
eu_einvoice/hooks.py | 9 +++++----
eu_einvoice/jinja.py | 21 +++++++++++++++++++++
eu_einvoice/public/img/fx-basic.png | Bin 0 -> 5556 bytes
eu_einvoice/public/img/fx-en16931.png | Bin 0 -> 5323 bytes
eu_einvoice/public/img/fx-extended.png | Bin 0 -> 5606 bytes
6 files changed, 42 insertions(+), 4 deletions(-)
create mode 100644 eu_einvoice/jinja.py
create mode 100644 eu_einvoice/public/img/fx-basic.png
create mode 100644 eu_einvoice/public/img/fx-en16931.png
create mode 100644 eu_einvoice/public/img/fx-extended.png
diff --git a/README.md b/README.md
index 004ee4c..8a82813 100644
--- a/README.md
+++ b/README.md
@@ -153,6 +153,22 @@ The following fields of the **Sales Invoice** are currently considered for the e
Document-level discounts are currently not supported, because the e invoice standard requires much more information than just the discount amount (e.g. the reason and applicable VAT rate).
+#### Embedding the Factur-X logo
+
+If you like, you can embed one of the official Factur-X logos in your invoice PDF. This way, a human can easily identify the invoice as a Factur-X eInvoice.
+
+To do this, use the `get_einvoice_logo` method in your jinja **Print Format**. This method returns a base64-encoded data URL, which can be used in an `
` tag.
+
+```jinja
+
+```
+
+The following logos are available:
+
+BASIC | EN 16931 | EXTENDED
+--- | --- | ---
+![BASIC](eu_einvoice/public/img/fx-basic.png) | ![EN 16931](eu_einvoice/public/img/fx-en16931.png) | ![EXTENDED](eu_einvoice/public/img/fx-extended.png)
+
### Purchase Invoice
To import a new eInvoice, create a new **E Invoice Import** and upload the XML or PDF file.
diff --git a/eu_einvoice/hooks.py b/eu_einvoice/hooks.py
index 4ed26b0..3416e09 100644
--- a/eu_einvoice/hooks.py
+++ b/eu_einvoice/hooks.py
@@ -77,10 +77,11 @@
# ----------
# add methods and filters to jinja environment
-# jinja = {
-# "methods": "eu_einvoice.utils.jinja_methods",
-# "filters": "eu_einvoice.utils.jinja_filters"
-# }
+jinja = {
+ "methods": [
+ "eu_einvoice.jinja.get_einvoice_logo",
+ ],
+}
# Installation
# ------------
diff --git a/eu_einvoice/jinja.py b/eu_einvoice/jinja.py
new file mode 100644
index 0000000..823c51f
--- /dev/null
+++ b/eu_einvoice/jinja.py
@@ -0,0 +1,21 @@
+import base64
+from pathlib import Path
+from typing import Literal
+
+PROFILE_TO_LOGO = {
+ "BASIC": "public/img/fx-basic.png",
+ "EN 16931": "public/img/fx-en16931.png",
+ "EXTENDED": "public/img/fx-extended.png",
+}
+
+
+def get_einvoice_logo(profile: Literal["BASIC", "EN 16931", "EXTENDED"]) -> str | None:
+ """Return the logo for the given profile, as a base64 encoded data URL."""
+ if profile not in PROFILE_TO_LOGO:
+ return None
+
+ logo_path = Path(__file__).parent / PROFILE_TO_LOGO.get(profile)
+ logo_bytes = logo_path.read_bytes()
+ logo_base64 = base64.b64encode(logo_bytes).decode("utf-8")
+
+ return f"data:image/png;base64,{logo_base64}"
diff --git a/eu_einvoice/public/img/fx-basic.png b/eu_einvoice/public/img/fx-basic.png
new file mode 100644
index 0000000000000000000000000000000000000000..76baec1e9da90ef095ba0c1fcfe4bcdd5a197a27
GIT binary patch
literal 5556
zcmbVQbyQSe*B&~DkQhQhLWYi^nHfMNq(QnFL6Mdk=@b!=kWgvqhM`Lu38h1ZMhp;!
z?*4|~`>yw0-=E)i*SY&V=ULC$`|h*Py6fH(rK_z9BxNE6002O>M@o;eJ?8c%#=}|#
zU<)?@fP1B@X`rn7LX(6AM#2CkXM_V8;N%Q2AOnozUybo!0L$M3ti5fFFiH>{+ivxY
z{}uxo;S>yT3Pv~;gWRo{5sr;Q27>-ek9A8+D@OtPmmV7etNgdCTQLZR4SE~#HXNMn
zc6clJM{^sR@*goJ6AZ`%#mcaNnhEO)j^(j>>|6pW2>_uW0GAH{z^26s0Pq0t`2i#%
z#5B@CCOJ}iC?T~JK7}|gsR#~GOjOzc@zmEZASUK*+Q-y_%&gL!+=}GnoUrgjH}^1I
zLq|rAhX5jB9C8Tu`AO(x4NPB*d>h?dTf06xxw*Zrj}P`2=N235+Z0r+-$Z@5zP!A-
zy1F?(zdk#?JUzWSKfl2;*H@=UhhGPV$QfZm;(9=O>6gAyn7B-#8
z+`-