Skip to content

farin/python-fakturoid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fakturoid.cz Python API

The Python interface to online accounting service Fakturoid.

This library is developed and maintained by Roman Krejcik ([email protected]). It is unoficial and no support from Fakturoid team can be claimed.

Installation

Install from PyPI

pip install fakturoid

or alternatively install development version directly from github

pip install -e git+git://github.com/farin/python-fakturoid#egg=fakturoid

Supported Python versions are 2.6+ and 3.x. Dependencies are requests, python-dateutil

Quickstart

Create context:

from fakturoid import Fakturoid

fa = Fakturoid('yourslug', '[email protected]', 'apikey038dc73...', 'YourApp ([email protected])')

Print 25 regular invoices in year 2013:

from datetime import date

for invoice in fa.invoices(proforma=False, since=date(2013,1,1))[:25]:
    print(invoice.number, invoice.total)

Delete subject with id 27:

subject = fa.subject(27)
fa.delete(subject)

And finally create new invoice:

from fakturoid import Invoice, InvoiceLine

invoice = Invoice(
    subject_id=28,
    number='2013-0108',
    due=10,
    issued_on=date(2012, 3, 30),
    taxable_fulfillment_due=date(2012, 3, 30),
    lines=[
        # use Decimal or string for floating values
        InvoiceLine(name='Hard work', unit_name='h', unit_price=40000, vat_rate=20),
        InvoiceLine(name='Soft material', quantity=12, unit_name='ks', unit_price="4.60", vat_rate=20),
    ]
)
fa.save(invoice)

print(invoice.due_on)

API

Fakturoid.account()

Returns Account instance. Account is readonly and can't be updated by API.

Fakturoid.subject(id)

Returns Subject instance.

Fakturoid.subjects(since=None, updated_since=None, custom_id=None)

Loads all subjects filtered by args. If since (date or datetime) parameter is passed, returns only subjects created since given date.

Fakturoid.subjects.search("General Motors")

Perform full text search on subjects

Fakturoid.invoce(id)

Returns Invoice instance.

Fakturoid.invoices(proforma=None, subject_id=None, since=None, updated_since=None, number=None, status=None, custom_id=None)

Use proforma=False/True parameter to load regular or proforma invoices only.

Returns list of invoices. Invoices are lazily loaded according to slicing.

fa.invoices(status='paid')[:100]   # loads 100 paid invoices
fa.invoices()[-1]   # loads first issued invoice (invoices are ordered from latest to first)

Fakturoid.fire_invoice_event(id, event, **args)

Fires basic events on invoice. All events are described in Fakturoid API docs.

Pay event can accept optional arguments paid_at and paid_amount

fa.fire_invoice_event(11331402, 'pay', paid_at=date(2018, 11, 17), paid_amount=2000)

Fakturoid.generator(id)

Returns Generator instance.

Fakturoid.generators(recurring=None, subject_id=None, since=None)

Use recurring=False/True parameter to load recurring or simple templates only.

Fakturoid.save(model)

Create or modify Subject, Invoice or Generator.

To modify or delete inoive lines simply edit lines

invoice = fa.invoices(number='2014-0002')[0]
invoice.lines[0].unit_price = 5000 # edit first item
del invoice.lines[-1]  # delete last item
fa.save(invoice)

Fakturoid.delete(model)

Delete Subject, Invoice or Generator.

subj = fa.subject(1234)
fa.delete(subj)            # delete subject

fa.delete(Subject(id=1234))   # or alternativelly delete is possible without object loading

Models

All models fields are named same as Fakturoid API.

Values are mapped to corresponding int, decimal.Decimal, datetime.date and datetime.datetime types.

Fakturoid.Account

http://docs.fakturoid.apiary.io/#reference/account

Fakturoid.Subject

http://docs.fakturoid.apiary.io/#reference/subjects

Fakturoid.Invoice
Fakturoid.InvoiceLine

http://docs.fakturoid.apiary.io/#reference/invoices

Fakturoid.Generator

http://docs.fakturoid.apiary.io/#reference/generators

Use InvoiceLine for generator lines

Fakturoid.Message

http://docs.fakturoid.apiary.io/#reference/messages