Skip to content

Commit

Permalink
feat: provide logos via jinja method (#59) (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
  • Loading branch information
mergify[bot] and barredterra authored Jan 10, 2025
1 parent 42f4fcc commit 2ffa7d4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<img>` tag.

```jinja
<img src="{{ get_einvoice_logo(doc.einvoice_profile) }}" alt="{{ doc.einvoice_profile }} e-invoice logo" />
```

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.
Expand Down
9 changes: 5 additions & 4 deletions eu_einvoice/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------
Expand Down
21 changes: 21 additions & 0 deletions eu_einvoice/jinja.py
Original file line number Diff line number Diff line change
@@ -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}"
Binary file added eu_einvoice/public/img/fx-basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added eu_einvoice/public/img/fx-en16931.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added eu_einvoice/public/img/fx-extended.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ffa7d4

Please sign in to comment.