Collmex API
===========
Collmex 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 at
http://www.collmex.de/cgi-bin/cgi.exe?1005,1,help,api.
The collmex object
------------------
The 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
>>> collmex = gocept.collmex.collmex.Collmex(
... os.environ['collmex_customer'], os.environ['collmex_company'],
... os.environ['collmex_username'], os.environ['collmex_password'])
Pre flight cleanup
------------------
First we need to clean up the Collmex environment:
>>> import gocept.collmex.testing
>>> gocept.collmex.testing.cleanup_collmex()
Transaction integration
-----------------------
gocept.collmex has support for transaction integration. All modifying calls are
buffered until the transaction is commited. XXX explain more.
>>> import transaction
Customers: ``create_customer`` and ``get_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)
2
The first customer is the generic one:
>>> customer = customers[0]
>>> customer['Satzart']
u'CMXKND'
>>> customer['Kundennummer']
u'9999'
>>> customer['Firma']
u'Allgemeiner Gesch\xe4ftspartner'
The second customer is one created during test setup:
>>> customer = customers[1]
>>> customer['Satzart']
u'CMXKND'
>>> customer['Kundennummer']
u'10000'
>>> customer['Firma']
u'Testkunden'
Products: ``create_product`` and ``get_products``
-------------------------------------------------
Products are created using the ``create_product`` method:
>>> 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']
u'Testprodukt'
Invoices: ``create_invoice`` and ``get_invoices``
-------------------------------------------------
Invoices are created using the ``create_invoice`` method:
>>> 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'] = u'item text \u2013 with non-ascii characters'
>>> item['Positionstyp'] = 0
>>> collmex.create_invoice([item])
Invoices can be looked up again, using the ``get_invoices`` method. However, as
discussed above the invoice was only registered for addition. Querying right
now does *not* return 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']
u'item text \u2013 with non-ascii characters'
Activities
----------
This section describes the API for activities (Taetigkeiten erfassen)
Create an activity
~~~~~~~~~~~~~~~~~~
A project with one set and an employee are required to submit activities:
>>> import datetime
>>> import gocept.collmex.testing
>>> gocept.collmex.testing.create_projects()
>>> gocept.collmex.testing.create_employee()
>>> act = gocept.collmex.model.Activity()
>>> act['Projekt Nr'] = '1' # Testprojekt
>>> act['Mitarbeiter Nr'] = '1' # Sebastian Wehrmann
>>> act['Satz Nr'] = '1' # TEST
>>> act['Beschreibung'] = u'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 using ``get_activities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Caution:** This method does not use the Collmex API as it does not provide
this functionality. It uses a browser to navigate to the download in the UI
and returns raw CSV data
>>> collmex.get_activities()
'Typkennung;Projekt;Mitarbeiter;Firma;Satz;Beschreibung;Datum;Von;Bis;Pausen\r\nCMXACT;1 Testprojekt;1 Sebastian Wehrmann;1 gocept apitest;1 Testprodukt;allgemeine T\xe4tigkeit;20120123;08:07;14:28;1:12\r\n'
Projects: ``get_projects``
--------------------------
Projects can be exported with the ``get_projects`` API. 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']
u'5,00'
>>> proj[1]['Satz']
u'9,65'
Caching
-------
Results 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
u'Testprodukt'
But after that, values are cached:
>>> collmex.get_products()[0]['Bezeichnung']
u'Testprodukt'
When the transaction ends, the cache is invalidated:
>>> transaction.commit()
>>> collmex.get_products()[0]['Bezeichnung']
cache miss
u'Testprodukt'
>>> collmex.get_products()[0]['Bezeichnung']
u'Testprodukt'
Remove tracing instrumentation:
>>> collmex._post = original_post
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | gocept.collmex-1.0.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 11 浏览量
2022-01-11
12:47:27
上传
评论
收藏 16KB GZ 举报
温馨提示
共29个文件
py:15个
txt:8个
pkg-info:2个
资源来自pypi官网。 资源全名:gocept.collmex-1.0.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
gocept.collmex-1.0.tar.gz (29个子文件)
gocept.collmex-1.0
PKG-INFO 12KB
README.txt 487B
CHANGES.txt 2KB
local.cfg-example 111B
bootstrap.py 2KB
src
gocept.collmex.egg-info
PKG-INFO 12KB
requires.txt 122B
not-zip-safe 1B
SOURCES.txt 848B
top_level.txt 7B
namespace_packages.txt 7B
dependency_links.txt 1B
gocept
collmex
README.txt 6KB
testing.py 4KB
utils.py 1KB
tests
test_doctest.py 287B
__init__.py 65B
test_collmex.py 918B
test_model.py 631B
test_thread.py 806B
test_testing.py 2KB
collmex.py 8KB
interfaces.py 2KB
__init__.py 65B
model.py 7KB
__init__.py 267B
setup.cfg 59B
setup.py 1KB
buildout.cfg 177B
共 29 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功