Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide logos via jinja method #59

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading