Giter Site home page Giter Site logo

invoicegenerator's Introduction

InvoiceGenerator

https://travis-ci.org/by-cx/InvoiceGenerator.svg?branch=master Latest Version

This is library to generate a simple invoices. Currently supported formats are PDF and XML for Pohoda accounting system. PDF invoice is based on ReportLab.

Example image of invoice

Installation

Run this command as root:

pip install InvoiceGenerator

If you want upgrade to new version, add --upgrade flag:

pip install InvoiceGenerator --upgrade

You can use setup.py from GitHub repository too:

python setup.py install

Documentation

Complete documentation is available on Read The Docs.

Example

Basic API

Define invoice data first:

import os

from tempfile import NamedTemporaryFile

from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator

# choose english as language
os.environ["INVOICE_LANG"] = "en"

client = Client('Client company')
provider = Provider('My company', bank_account='2600420569', bank_code='2010')
creator = Creator('John Doe')

invoice = Invoice(client, provider, creator)
invoice.currency_locale = 'en_US.UTF-8'
invoice.add_item(Item(32, 600, description="Item 1"))
invoice.add_item(Item(60, 50, description="Item 2", tax=21))
invoice.add_item(Item(50, 60, description="Item 3", tax=0))
invoice.add_item(Item(5, 600, description="Item 4", tax=15))

Note: Due to Python's representational error, write numbers as integer tax=10, Decimal tax=Decimal('10.1') or string tax='1.2' to avoid getting results with lot of decimal places.

PDF

Generate PDF invoice file:

from InvoiceGenerator.pdf import SimpleInvoice

pdf = SimpleInvoice(invoice)
pdf.gen("invoice.pdf", generate_qr_code=True)

Pohoda XML

Generate XML invoice file:

from InvoiceGenerator.pohoda import SimpleInvoice

pdf = SimpleInvoice(invoice)
pdf.gen("invoice.xml")

Note: Pohoda uses three tax rates: none: 0%, low: 15%, high: 21%. If any item doesn't meet those percentage, the rateVat parameter will not be set for those items resulting in 0% tax rate.

Only SimpleInvoice is currently supported for Pohoda XML format.

Hacking

Fork the repository on github and write code. Make sure to add tests covering your code under /tests/. You can run tests using:

python setup.py test

Then propose your patch via a pull request.

Documentation is generated from doc/source/ using Sphinx:

python setup.py build_sphinx

Then head to doc/build/html/index.html.

invoicegenerator's People

Contributors

by-cx avatar hashar avatar lejmr avatar mezka avatar pauloangelo avatar petrdlouhy avatar rbas avatar timthelion avatar truhlik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

invoicegenerator's Issues

python2: DejaVuSans.ttf not found

reportlab.pdfbase.ttfonts.TTFError: Can't open file "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"

Fonts are installed on another path on my system (only know about Arch Linux right now, can test on FreeBSD too if needed).

user@machine [1] % locate DejaVuSans.ttf                                    
/usr/share/fonts/TTF/DejaVuSans.ttf
/usr/share/texmf-dist/fonts/truetype/public/dejavu/DejaVuSans.ttf

Invoice

I want to involve software for free

Přetékání položek na faktuře

Ahoj,

pokud přidám moc položek na fakturu, tak mi celý spodek faktury odjede mimo hranici stránky, takže není vidět čárový kód, cena a další věci. Bylo by potřeba, aby se v takovém případě odsunuly další položky na další stránku.

Pokusil bych se vyřešit tento problém sám, ale potřeboval bych napřed vědět, jestli jen něco nedělám špatně (jestli nejde víc stránek nějak zapnout), a případně jestli někdo neví, jak je to potřeba udělat, aby to bylo v pořádku z hlediska zákona (označení počtu stránek a tak).

bug in QR code generator

Hi,

seems there is a bug in QR generator if you create Invoice with bank_account and bank_code. QR code is corrupted in this case.

Change currency to USD$

For some reason when I run this script with all of the example data a get a PDF in the Czech Koruna? Any way to change this to USD$?

Travis tests not passing

Before pulling PRs #38 #37 #34 it would be needed to fix Travis tests, that broke since the last commit into master. It was probably caused by change in dependencies.

The tests must be fixed prior pulling those requests.

python3: ImportError: No module named 'conf'

Traceback (most recent call last):
  File "main.py", line 2, in <module>
      from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator
  File "/usr/lib/python3.4/site-packages/InvoiceGenerator/api.py", line 6, in <module>
      from conf import _
ImportError: No module named 'conf'

TypeError: patchedDrawPath() takes 2 positional arguments but 4 were given

TypeError: patchedDrawPath() takes 2 positional arguments but 4 were given
  File "django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "newrelic/hooks/framework_django.py", line 563, in wrapper
    return wrapped(*args, **kwargs)
  File "django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "dpnk/company_admin_views.py", line 345, in dispatch
    ret_val = super().dispatch(request, *args, **kwargs)
  File "dpnk/views_permission_mixins.py", line 51, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "dpnk/views_permission_mixins.py", line 182, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "braces/views/_access.py", line 102, in dispatch
    request, *args, **kwargs)
  File "newrelic/hooks/framework_django.py", line 953, in wrapper
    return wrapped(*args, **kwargs)
  File "django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "django/views/generic/edit.py", line 172, in post
    return super().post(request, *args, **kwargs)
  File "django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "dpnk/company_admin_views.py", line 332, in form_valid
    self.object.save()
  File "python3.6/contextlib.py", line 52, in inner
    return func(*args, **kwds)
  File "dpnk/models/invoice.py", line 259, in save
    super().save(*args, **kwargs)
  File "model_utils/models.py", line 38, in save
    super().save(*args, **kwargs)
  File "django/db/models/base.py", line 744, in save
    force_update=force_update, update_fields=update_fields)
  File "django/db/models/base.py", line 793, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "django/dispatch/dispatcher.py", line 175, in send
    for receiver in self._live_receivers(sender)
  File "django/dispatch/dispatcher.py", line 175, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "dpnk/models/invoice.py", line 344, in create_and_send_invoice_files
    invoice_gen.make_invoice_pdf(temp_pdf, invoice_data)
  File "dpnk/invoice_gen.py", line 96, in make_invoice_pdf
    pdf_file.gen(outfile_pdf, generate_qr_code=True)
  File "InvoiceGenerator/pdf.py", line 144, in gen
    self._drawMain()
  File "InvoiceGenerator/pdf.py", line 199, in _drawMain
    self.pdf.drawPath(path, True, True)

English language?

I see that the language is set in conf.py but I can't find it anywhere else. How do I make InvoiceGenerator output in English? Do you need a messages file?

Work around on windows.

On windows it gives 2 error,

  1. Not able to find DejaVu.ttf font
  2. Not able to set locale.

To solve first you have to replace DejaVu with Vera (default font in reportlab) & DejaVu-Bold with VeraBd. Update FONT_PATH in conf.py. Point it towards Vera.ttf under reportlab directory.

For second, you have to change in pdf.py in line 69,
locale.setlocale(locale.LC_ALL, str('american'))
Locale setting is mess on windows. To select any other locale setting put Language String from https://msdn.microsoft.com/en-us/library/39cwe7zf(vs.71).aspx

Use other locale than "en" doesn't change the language

I've modified the $LANG variable several times but the output PDF is always the same. Have you implemented any functionality related to this?

Maybe I can add more languages like Spanish if you give me a dictionary file for the translations. Also, you can let me know what should I change to implement this "dictionary" functionality.

Thanks and regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.