Package: gocept.collmex
ContentsIntroductionCredentialsCollmex APIThe collmex objectPre flight cleanupTransaction integrationCustomers:create_customerandget_customersProducts:create_productandget_productsInvoices:create_invoiceandget_invoicesActivitiesCreate an activityExport usingget_activitiesProjects:get_projectsCachingChanges2.0.1 (2023-08-23)2.0 (2023-08-23)1.9 (2019-09-02)1.8.3 (2018-03-16)1.8.2 (2017-01-23)1.8.1 (2016-06-09)1.8.0 (2016-01-27)1.7.0 (2014-09-04)1.6.0 (2014-08-18)1.5.1 (2013-12-09)1.5.0 (2013-12-09)1.4.4 (2013-09-25)1.4.3 (2013-09-24)1.4.2 (2013-09-23)1.4.1 (2013-09-16)1.4 (2013-09-13)1.3 (2013-02-22)1.2.1 (2012-03-09)1.2 (2012-02-21)1.1.1 (2012-02-17)1.1 (2012-02-17)1.0 (2012-01-23)0.9 (2012-01-20)0.8 (2012-01-20)0.7 (2009-11-05)0.6 (2009-02-16)0.5.1 (2009-01-08)0.5 (2008-12-19)0.4 (2008-12-11)0.3.1 (2008-12-02)0.3 (2008-12-01)0.2 (2008-11-28)0.1 (2008-10-14)IntroductionCollmex is an online ERP system for (small) companies with a focus on simple
accounting. <http://www.collmex.de> (Note: Collmex is Germany-based but seems
to support English. You’re bound to stumble over German strings, though.)This package aims to provide pythonic bindings to program against Collmex’
API. It includes transaction management for integration with the ZODB or other
databases that can integrate with thetransactionpackage.CredentialsTo initialize a connection to the collmex server, login-credentials are required. These can be given explicitely when thegocept.collmex.collmex.Collmexobject is created or via an ini file namedcollmex.ini.
The ini file must live in the project directory or any of it’s parent directories, e.g. it is possible to placecollmex.iniin your home directory to use those credentials for all of your projects.
The ini file must contain the section[credentials]for production and[test-credentials]for testing purposes.
Each section must have the following options:customer_id,company_id,usernameandpassword.
The filecollmex.ini-examplecan be used as a template.Example:[credentials]
customer_id = 42555
company_id = 1
username = realuser
password = realpassword

[test-credentials]
customer_id = 41222
company_id = 1
username = testuser
password = testpasswordCollmex APICollmex provides a POST- and CSV-based API, which is encapsulated into a
utility that provides methods for the various CSV record types.  API
documentation is available athttp://www.collmex.de/cgi-bin/cgi.exe?1005,1,help,api.The collmex objectThe collmex object is a central place to access collmex. In the Zope 3 jargon
it is a global utility:>>> import os
>>> import gocept.collmex.collmex
>>> os.environ['collmex_credential_section'] = 'test-credentials'
>>> collmex = gocept.collmex.collmex.Collmex()Pre flight cleanupFirst we need to clean up the Collmex environment:>>> import gocept.collmex.testing
>>> gocept.collmex.testing.cleanup_collmex()Transaction integrationgocept.collmex has support for transaction integration. All modifying calls are
buffered until the transaction is commited. XXX explain more.>>> import transactionCustomers:create_customerandget_customers>>> customer = gocept.collmex.model.Customer()
>>> customer['Kundennummer'] = 10000
>>> customer['Firma'] = 'Testkunden'
>>> collmex.create(customer)
>>> transaction.commit()Customers can be listed using the get_customers method:>>> customers = collmex.get_customers()
>>> customers
[<gocept.collmex.model.Customer object at 0x...>, <gocept.collmex.model.Customer object at 0x...>]
>>> len(customers)
2The first customer is the generic one:>>> customer = customers[0]
>>> customer['Satzart']
'CMXKND'
>>> customer['Kundennummer']
'9999'
>>> customer['Firma']
'Allgemeiner Geschäftspartner'The second customer is one created during test setup:>>> customer = customers[1]
>>> customer['Satzart']
'CMXKND'
>>> customer['Kundennummer']
'10000'
>>> customer['Firma']
'Testkunden'Products:create_productandget_productsProducts are created using thecreate_productmethod:>>> product = gocept.collmex.model.Product()
>>> product['Produktnummer'] = 'TEST'
>>> product['Bezeichnung'] = 'Testprodukt'
>>> product['Produktart'] = 1 # Dienstleistung
>>> product['Basismengeneinheit'] = 'HR'
>>> product['Verkaufs-Preis'] = 5
>>> collmex.create(product)
>>> transaction.commit()
>>> collmex.get_products()[0]['Bezeichnung']
'Testprodukt'Invoices:create_invoiceandget_invoicesInvoices are created using thecreate_invoicemethod:>>> import datetime
>>> start_date = datetime.datetime.now()
>>> item = gocept.collmex.model.InvoiceItem()
>>> item['Kunden-Nr'] = '10000'
>>> item['Rechnungsnummer'] = 100000
>>> item['Menge'] = 3
>>> item['Produktnummer'] = 'TEST'
>>> item['Rechnungstext'] = 'item text \u2013 with non-ascii characters'
>>> item['Positionstyp'] = 0
>>> collmex.create_invoice([item])Invoices can be looked up again, using theget_invoicesmethod. However, as
discussed above the invoice was only registered for addition. Querying right
now doesnotreturn the invoice:>>> collmex.get_invoices(customer_id='10000', start_date=start_date)
[]After committing, the invoice is found:>>> transaction.commit()
>>> collmex.get_invoices(customer_id='10000',
...                      start_date=start_date)[0]['Rechnungstext']
'item text – with non-ascii characters'ActivitiesThis section describes the API for activities (Taetigkeiten erfassen)Create an activityA project with one set and an employee are required to submit activities:>>> import datetime
>>> import gocept.collmex.testing
>>> gocept.collmex.testing.create_project('Testprojekt', collmex=collmex)
>>> gocept.collmex.testing.create_employee(collmex)
>>> act = gocept.collmex.model.Activity()
>>> act['Projekt Nr'] = '1' # Testprojekt
>>> act['Mitarbeiter Nr'] = '1' # Sebastian Wehrmann
>>> act['Satz Nr'] = '1' # TEST
>>> act['Beschreibung'] = 'allgemeine T\xe4tigkeit'
>>> act['Datum'] = datetime.date(2012, 1, 23)
>>> act['Von'] = datetime.time(8, 7)
>>> act['Bis'] = datetime.time(14, 28)
>>> act['Pausen'] = datetime.timedelta(hours=1, minutes=12)
>>> collmex.create(act)
>>> transaction.commit()Export usingget_activitiesget_activitiesreturns Activity objects.Attention!In previous versions this method returnd a raw CSV string. This
was due to Collmex not having an actual API.>>> activities = collmex.get_activities()
>>> activities[0]['Beschreibung']
'allgemeine T\xe4tigkeit'Projects:get_projectsProjects can be exported with theget_projectsAPI. It returns an entry
for every project set (Projektsatz) of each project (Projekt):>>> proj = collmex.get_projects()
>>> len(proj)
2
>>> proj[0]['Projektnummer'] == proj[1]['Projektnummer']
True>>> proj[0]['Satz']
'5,00'
>>> proj[1]['Satz']
'9,65'
>>> proj[0]['Inaktiv']
'0'CachingResults queried from Collmex are cached for the duration of the transaction.To demonstrate this, we instrument the _post() method that performs the actual
HTTP communication to show when it is called:>>> original_post = collmex._post
>>> def tracing_post(self, *args, **kw):
...     print('cache miss')
...     return original_post(*args, **kw)
>>> collmex._post = tracing_post.__get__(collmex, type(collmex))The first time in an transaction is retrieved from Collmex, of course:>>> transaction.abort()
>>> collmex.get_products()[0]['Bezeichnung']
cache miss
'Testprodukt'But after that, values are cached:>>> collmex.get_products()[0]['Bezeichnung']
'Testprodukt'When the transaction ends, the cache is invalidated:>>> transaction.commit()
>>> collmex.get_products()[0]['Bezeichnung']
cache miss
'Testprodukt'>>> collmex.get_products()[0]['Bezeichnung']
'Testprodukt'Remove tracing instrumentation:>>> collmex._post = original_postChanges2.0.1 (2023-08-23)Mark wheel as not universal.2.0 (2023-08-23)Drop support for Python 2.7, 3.5, 3.6.Add support for Python 3.9, 3.10, 3.11.Avoid password exhaustion by using invalid username for tests.Fix the tests to use fewer connections.1.9 (2019-09-02)Drop support for Python 3.3 and 3.4.Add support for Python 3.6, 3.7 and 3.8b4.Migrate code to GitHub.Update tests to new Collmex URLs.1.8.3 (2018-03-16)Implemented CMXABO, only applicable for “collmex Verein”.1.8.2 (2017-01-23)ImplementedMITGLIED_GETasget_members()andCMXMGDasmodels.Member, both only applicable for “collmex Verein”.1.8.1 (2016-06-09)ExtendProjectto retrieve budget and summed up work via API.1.8.0 (2016-01-27)Declared compatibility with Python 3.4.Drop support for Python 3.2.Made sure tests don’t use invalid credentials on test account too many times
in a row.RaiseValueErrorif the Collmex website returned an error duringCollmex.browser_login. Until now the error was hidden, but the following
action failed. In particular this should help to spot invalid credentials.1.7.0 (2014-09-04)Use collmex.ini file given by the path in environment variableCOLLMEX_INIif present, only otherwise look upward from the current
directory.Don’t log the password in our debug output.1.6.0 (2014-08-18)Un-deprecate methodCollmex.create_invoice, it now takes care of
automatically allocating invoice ids.Addgocept.collmex.testing.ConsoleDumputility that fakes a collmex
connection, but only logs method calls.1.5.1 (2013-12-09)Fix brown bag release 1.5.01.5.0 (2013-12-09)Added methods to Activity to parse/calculate the dates, times, breaks,
duration.1.4.4 (2013-09-25)Improve check for invalid credentials whengocept.collmex.collmex.Collmexis created.Yield more detailed information when parsing of the ini file failed.1.4.3 (2013-09-24)Fix the check for invalid credentials whengocept.collmex.collmex.Collmexis created.1.4.2 (2013-09-23)Credentials to log into Collmex can be given via ancollmex.inifile.1.4.1 (2013-09-16)Creation of test activities is now fully customizable1.4 (2013-09-13)gocept.collmex is now compatible with Python 3.2 and Python 3.3!1.3 (2013-02-22)Implement activities API (#11954).1.2.1 (2012-03-09)Fixgocept.collmex.collmex.Collmex.browser_login()after collmex website
changed wich included a rename of form elements.1.2 (2012-02-21)Note: This version was accidentally released without the changes in 1.1.1,
however, the release itself contained the changes of 1.1 and thus isn’t
broken.AddInaktivattribute onCMXPRJ(projects)1.1.1 (2012-02-17)Rectify previous brown-bag release.1.1 (2012-02-17)Do not honour Collmex’ robots.txt as of 2012-02-09. :(1.0 (2012-01-23)Forced usage of Python 2.7.Added testing helperget_collmexto create a collmex object from
environment variables.Made testing helpercollmex_login()a method:gocept.collmex.collmex.Collmex.browser_login()Modified signature of testing helpercreate_activity, so it no longer
needs a parameter.0.9 (2012-01-20)Added testing helpercreate_activity.0.8 (2012-01-20)Added API for retrieving activities (get_activities).Updated tests and test infrastructure to recent changes in Collmex.0.7 (2009-11-05)Added API for retrieving projects and creation of activities.0.6 (2009-02-16)Make models robust against API changes so they don’t immediately break when
the record becomes longer.Updated customer model to current API.0.5.1 (2009-01-08)Fixed multi-threading bug: thread-local data needs to be intialized for each
thread.0.5 (2008-12-19)Values returned from Collmex are converted to unicode.Cache results for the duration of the transaction.0.4 (2008-12-11)Addedget_productsandcreate_product.Addedcreate_customer.gocept.collmex.testing.cleanup_collmex() now only deletes any existing data,
it does not add any sample customers or products, use the API for that.0.3.1 (2008-12-02)Python 2.5 compatibility.0.3 (2008-12-01)Using Windows-1252 as encoding when uploading data (used to be ISO-8859-1).Fixed transaction integration when upload fails.0.2 (2008-11-28)Modifications for changed Collmex API.Addedget_customersto query customers (APICUSTOMER_GET).0.1 (2008-10-14)first release. Supports getting and storing invoices.