Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

ibanity (Ibanity in Così)

This document explains how the lino_xl.lib.ibanity plugin is used in Lino Così.

Note

Code snippets in this document (lines starting with >>>) get tested as part of our development workflow. The following initialization snippet tells you which demo project is being used.

>>> from lino_book.projects.cosi1.startup import *

The tests in this document are skipped unless you also have Ibanity credentials installed. See How to set up your credentials for details.

>>> if dd.plugins.ibanity.credentials is None:
...     pytest.skip('this doctest requires Ibanity credentials')
>>> ar = rt.login("robin")
>>> dd.plugins.ibanity.with_suppliers
False
>>> ar.show(ibanity.OnboardingStates)
Traceback (most recent call last):
...
AttributeError: module 'lino_xl.lib.ibanity.models' has no attribute 'OnboardingStates'
>>> ar.show(ibanity.Suppliers)
Traceback (most recent call last):
...
AttributeError: module 'lino_xl.lib.ibanity.models' has no attribute 'Suppliers'
>>> dd.plugins.ibanity.supplier_id
'273c1bdf-6258-4484-b6fb-74363721d51f'

Tidy up after previous test runs:

>>> def tidy_up():
...     VoucherStates = rt.models.accounting.VoucherStates
...     rt.models.ibanity.InboundDocument.objects.all().delete()
...     rt.models.ibanity.OutboundInfo.objects.all().delete()
...     qs = dd.plugins.ibanity.outbound_model.objects.filter(state=VoucherStates.sent)
...     qs.update(state=VoucherStates.registered)
>>> tidy_up()

In the beginning our Outbox is empty:

>>> rt.show(ibanity.Outbox)
Keine Daten anzuzeigen

Fill the outbox with invoices to send:

>>> with ar.print_logger("DEBUG"):
...     rt.models.ibanity.collect_outbound(ar)
Collect outbound invoices into outbox
Scan 1 outbound journal(s): ['SLS']
Collect 5 new invoices into outbox
>>> rt.show(ibanity.Outbox)
====================== ===================== ================= ================= ================== ==============
 Verkaufsrechnung       Partner               MwSt.-Regime      Erfassungsdatum   Total ohne MwSt.   MwSt.
---------------------- --------------------- ----------------- ----------------- ------------------ --------------
 SLS 1/2014             Bestbank              MwSt.-pflichtig   07.01.14          2 999,85           629,97
 SLS 3/2014             Bäckerei Ausdemwald   MwSt.-pflichtig   09.01.14          679,81             142,76
 SLS 4/2014             Bäckerei Mießen       MwSt.-pflichtig   10.01.14          280,00             58,80
 SLS 5/2014             Bäckerei Schmitz      MwSt.-pflichtig   11.01.14          535,00             112,35
 SLS 6/2014             Garage Mergelsberg    MwSt.-pflichtig   07.02.14          1 110,16           203,87
 **Total (5 Zeilen)**                                                             **5 604,82**       **1 147,75**
====================== ===================== ================= ================= ================== ==============
>>> ses = dd.plugins.ibanity.get_ibanity_session()

Send outgoing documents:

>>> with ar.print_logger("DEBUG"):
...     ibanity.send_outbound(ses, ar)
...
Send outbound documents
Gonna send SLS 1/2014
Make .../media/xml/2014/SLS-106.xml from SLS 1/2014 ...
Validate SLS-106.xml against /home/luc/work/xl/lino_xl/lib/vat/XSD/PEPPOL-EN16931-UBL.sch ...
Made .../media/xml/2014/SLS-106.xml
Ibanity response {'attributes': {'createdAt': '2019-07-17T07:31:30.763402Z', 'status': 'created'}, 'id': '94884e80-cc4a-4583-bd4a-288095c7876f', 'relationships': {'supplier': {'data': {'id': '273c1bdf-6258-4484-b6fb-74363721d51f', 'type': 'supplier'}}}, 'type': 'peppolInvoice'}
Gonna send SLS 3/2014
Make .../media/xml/2014/SLS-108.xml from SLS 3/2014 ...
Validate SLS-108.xml against /home/luc/work/xl/lino_xl/lib/vat/XSD/PEPPOL-EN16931-UBL.sch ...
Made .../media/xml/2014/SLS-108.xml
Ibanity response {'attributes': {'createdAt': '2019-07-17T07:31:30.763402Z', 'status': 'created'}, 'id': '94884e80-cc4a-4583-bd4a-288095c7876f', 'relationships': {'supplier': {'data': {'id': '273c1bdf-6258-4484-b6fb-74363721d51f', 'type': 'supplier'}}}, 'type': 'peppolInvoice'}
Gonna send SLS 4/2014
Make .../media/xml/2014/SLS-109.xml from SLS 4/2014 ...
Validate SLS-109.xml against /home/luc/work/xl/lino_xl/lib/vat/XSD/PEPPOL-EN16931-UBL.sch ...
Made .../media/xml/2014/SLS-109.xml
Ibanity response {'attributes': {'createdAt': '2019-07-17T07:31:30.763402Z', 'status': 'created'}, 'id': '94884e80-cc4a-4583-bd4a-288095c7876f', 'relationships': {'supplier': {'data': {'id': '273c1bdf-6258-4484-b6fb-74363721d51f', 'type': 'supplier'}}}, 'type': 'peppolInvoice'}
Gonna send SLS 5/2014
Make .../media/xml/2014/SLS-110.xml from SLS 5/2014 ...
Validate SLS-110.xml against /home/luc/work/xl/lino_xl/lib/vat/XSD/PEPPOL-EN16931-UBL.sch ...
Made .../media/xml/2014/SLS-110.xml
Ibanity response {'attributes': {'createdAt': '2019-07-17T07:31:30.763402Z', 'status': 'created'}, 'id': '94884e80-cc4a-4583-bd4a-288095c7876f', 'relationships': {'supplier': {'data': {'id': '273c1bdf-6258-4484-b6fb-74363721d51f', 'type': 'supplier'}}}, 'type': 'peppolInvoice'}
Gonna send SLS 6/2014
Make .../media/xml/2014/SLS-111.xml from SLS 6/2014 ...
Validate SLS-111.xml against /home/luc/work/xl/lino_xl/lib/vat/XSD/PEPPOL-EN16931-UBL.sch ...
Made .../media/xml/2014/SLS-111.xml
Ibanity response {'attributes': {'createdAt': '2019-07-17T07:31:30.763402Z', 'status': 'created'}, 'id': '94884e80-cc4a-4583-bd4a-288095c7876f', 'relationships': {'supplier': {'data': {'id': '273c1bdf-6258-4484-b6fb-74363721d51f', 'type': 'supplier'}}}, 'type': 'peppolInvoice'}

The Outbox table is now empty, and the invoices have moved to the Sent table.

>>> rt.show(ibanity.Outbox)
Keine Daten anzuzeigen
>>> rt.show(ibanity.Sent, language="en")
=============== ===================== ============================ ========= =================
 Sales invoice   Partner               Created at                   State     Transmission ID
--------------- --------------------- ---------------------------- --------- -----------------
 SLS 1/2014      Bestbank              2019-07-17 07:31:30.763402   Created
 SLS 3/2014      Bäckerei Ausdemwald   2019-07-17 07:31:30.763402   Created
 SLS 4/2014      Bäckerei Mießen       2019-07-17 07:31:30.763402   Created
 SLS 5/2014      Bäckerei Schmitz      2019-07-17 07:31:30.763402   Created
 SLS 6/2014      Garage Mergelsberg    2019-07-17 07:31:30.763402   Created
=============== ===================== ============================ ========= =================

The status is “created” and they do not yet have any transmission ID. This will change with the next synchronization step:

>>> with ar.print_logger("DEBUG"):
...     ibanity.followup_outbound(ses, ar)
...
Check outbound documents
SLS 1/2014 (ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5) state created becomes sent
SLS 3/2014 (ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5) state created becomes sent
SLS 4/2014 (ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5) state created becomes sent
SLS 5/2014 (ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5) state created becomes sent
SLS 6/2014 (ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5) state created becomes sent
>>> rt.show(ibanity.Sent)
================== ===================== ============================ =========== =======================================
 Verkaufsrechnung   Partner               Created at                   Zustand     Transmission ID
------------------ --------------------- ---------------------------- ----------- ---------------------------------------
 SLS 1/2014         Bestbank              2019-07-17 07:31:30.763402   Versendet   ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5
 SLS 3/2014         Bäckerei Ausdemwald   2019-07-17 07:31:30.763402   Versendet   ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5
 SLS 4/2014         Bäckerei Mießen       2019-07-17 07:31:30.763402   Versendet   ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5
 SLS 5/2014         Bäckerei Schmitz      2019-07-17 07:31:30.763402   Versendet   ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5
 SLS 6/2014         Garage Mergelsberg    2019-07-17 07:31:30.763402   Versendet   ba6c26fa-f47c-4ef1-866b-71e4ef02f15a5
================== ===================== ============================ =========== =======================================
>>> with ar.print_logger("DEBUG"):
...     ibanity.check_inbox(ses, ar)
...
Check our inbox
We got a new document 431cb851-5bb2-4526-8149-5655d648292f
>>> rt.show(ibanity.Inbox)
============================ ====================================== ======================================= ==========
 Created at                   DocumentId                             Transmission ID                         Rechnung
---------------------------- -------------------------------------- --------------------------------------- ----------
 ...                          431cb851-5bb2-4526-8149-5655d648292f   c038dbdc1-26ed-41bf-9ebf-37g3c4ceaa58
============================ ====================================== ======================================= ==========

Tidy up to avoid side effects in following tests:

>>> tidy_up()