Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Python API instead of YAML (#1)
Browse files Browse the repository at this point in the history
Added locales and made code easily and efficiently usable from Django

Can now be used from Python thanks to data structures instead of YAML.
Which means it can be used from django as well.

Replaced pybars3 by Django's template engine.

Made text a bit smaller.

No longer calculating totals, since they are already calculated from user's code.

Business's information and PDF page counter are now in the template file to allow easy edits.

* Moved templates folder + localizing dates + style edits

- ./documents/invoice/template -> ./template
- Dates are no localized using Babel.
- Removed wrapping in the table headers
- Centered table headers and short data cells
- Added localization

* Translated to French and German.

* Additional information can be added through the `Executive` model

* Additional information are now in the bottom center
+ logo is now SVG
+ added shipping total
+ gross total is now bold
+ date to pay until can now be omitted

* Must now specify the product's reference + discounts
 - Now showing product reference instead of the product position
 - Now showing the sum of discounts
 - Added a filter: base65, will be useful in the future in an external way.
  • Loading branch information
NyanKiyoshi authored Feb 19, 2018
1 parent 80c4aae commit 846adc0
Show file tree
Hide file tree
Showing 23 changed files with 803 additions and 291 deletions.
2 changes: 2 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[jinja2: **/template/**.html]
encoding = utf-8
73 changes: 0 additions & 73 deletions buildpdf.py

This file was deleted.

33 changes: 0 additions & 33 deletions documents/invoice/data.yml

This file was deleted.

84 changes: 0 additions & 84 deletions documents/invoice/template/index.html

This file was deleted.

Binary file removed documents/invoice/template/logo.png
Binary file not shown.
99 changes: 0 additions & 99 deletions documents/invoice/template/style.css

This file was deleted.

1 change: 1 addition & 0 deletions invoice_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'invoice_generator.apps.InvoiceGeneratorConfig'
7 changes: 7 additions & 0 deletions invoice_generator/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class InvoiceGeneratorConfig(AppConfig):
name = 'invoice_generator'
verbose_name = _("Invoice Generator")
33 changes: 33 additions & 0 deletions invoice_generator/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
import os.path

from django.template.loader import get_template
from weasyprint import HTML

from .models import *


BASE_PATH = os.path.join(os.path.dirname(__file__))
BASE_URL = os.path.join(BASE_PATH, 'templates')


def generate_pdf(
currency: str, invoice: Invoice,
template=None, static_path=BASE_URL):

if not template:
template = get_template('index.html')

ctx = dict(
invoice=invoice,
order=invoice.order,
currency=currency,
executive=invoice.vendor.executive,
vendor=invoice.vendor,
billing_address=invoice.billing_address,
)

html_text = template.render(ctx)
weasytemplate = HTML(string=html_text, base_url=static_path)

return weasytemplate
Binary file added invoice_generator/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 846adc0

Please sign in to comment.