Skip to main content

Abstraction for e-conomic.com API

Project description

pyconomics is a python client/abstraction for the e-conomic API (e-conomic.com)


Installation
------------

pip install pyconomic


Basic Usage
-----------

# startup
>>> import pyconomic
>>> from pyconomic import models
>>> pycon = pyconomic.Pyconomic(agreement_nr, user_id, password)

# get / create base models
>>> random_account = pycon.find(models.DebtorGroup)[0].account
>>> terms = pycon.get(models.TermOfPayment, name='Net 8 days')
>>> debtor_group = pycon.get_or_create(models.DebtorGroup, name='Test Group', number=123, account=random_account)
>>> currency = pycon.get_or_create(models.Currency, code='DKK')

# create debtor - you can also use "pycon.create(models.Debtor, ..)", all "create_" methods are facade methods to help construct all the input
>>> john = pycon.create_debtor(debtor_group, 'John Doe', terms, pyconomic.VatZone.Domestic, currency, address='Somewhere', city='LongAgo', country='FarFarAway')

# pyconomic will cache all instances, so the john-instance should be in the any new query of debtors from the server
>>> debtors = pycon.find(models.Debtor, partial_name='John*')
>>> john in debtors and debtors[0].name == 'John Doe'
True

# create products
>>> product_group = pycon.find(models.ProductGroup)[0] # use a random product group
>>> service = pycon.create_product('1000', product_group, 'Consulting Service', 300, description='I Do Stuff')
>>> thing = pycon.create_product('1001', product_group, 'Thing', 1200, description='Thing in black')

# create orders
>>> order1 = pycon.create_order(john, products=[service, thing])

# first time accessing a list-property like "orders" will do a server-call, and cache result for next access
>>> john.orders
[<Order ...>]

# which means that any new orders will not show up on the orders property
>>> order2 = pycon.create_order(john, products=[thing])
>>> len(john.orders)
1

# use fetch to ask the server for new data
>>> john.orders.fetch()
[<Order ...>, <Order ...>]
>>> len(john.orders)
2

# instances also has a fetch.. Reload the product data of the first order-line in the first of johns orders (for the fun of it):
>>> john.orders[0].lines[0].product.fetch()
<Product ...>

# updating data - pycon.commit() will send all changes to server
>>> orderline = john.orders[0].lines[0]
>>> orderline.quantity = 3
>>> pycon.get_all_changes()[models.OrderLine]
[<Changes <OrderLine ...> {'quantity': 3}>]
>>> pycon.commit()
>>> pycon.get_all_changes()[models.OrderLine]
[]
>>> orderline.quantity
3

# upgrade order to invoice (must not be sent)
>>> pycon.upgrade_to_invoice(order1)
<CurrentInvoice ...>

# send order
>>> order2.is_sent
False
>>> pycon.send_order(order2)
>>> order2.fetch().is_sent
True

# save order-pdf to the file "orderpdf.pdf" in the current working directory
>>> order2.pdf.save('orderpdf')

# delete everything again, orders seems be deleted as the debtor is deleted
>>> john.delete()
>>> service.delete()
>>> thing.delete()


Notes
-----

* Model instances are cached and reused based on their handle
* The "find", "get", and "get_or_create" requires available "TYPE_FindBy[X]" server-method, and will make multiple server-calls if needed
* Once a single instance needs its data, it will fetch the data of all instances in the cache by that type
* List properties require a separate server-call:
[debtor.invoices for debtor in debtors] would be as many server-calls as there's debtors, while getting attribute "name" is only 1 server-call to get all names
* Changes in data is only saved on pycon.commit() except for Create and Delete which saves immediately

To-Do
-----

* add "updated since" query
* create more facade methods, only has a few (create_order, create_products, ...) - use pycon.create([Model], **arguments) for the rest
* update cache on create; doing create_orderline should update all the "order.lines" properties - use ".fetch()" to update data instead
* properties are missing a "read_only" state, so the user wont try to change data that cannot be saved
* see if possible to create a data-model that is more IDE auto-complete friendly
* add missing enums, only got for VatZone
*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyconomic-0.1.2.tar.gz (15.0 kB view details)

Uploaded Source

File details

Details for the file pyconomic-0.1.2.tar.gz.

File metadata

  • Download URL: pyconomic-0.1.2.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyconomic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 aa08a2ffac13be23c3894797b82baa5a30539bad1517070d9931d75ba3263247
MD5 24876970bee2bb1da37670a8eb8f366e
BLAKE2b-256 7805970ae44373ed477e357a2d33adc0c5749dc572870afdae8f18c799e52fd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page