This is Python implementation for the Pos Partner REST API.
- Simple, reliable, and elegant.
- No need to generate authentication and timestamps by yourself, the wrapper does it for you.
- Module format functionality the same as pos officail document.
- Good Response exception handling !
- Have two ways to use, compatible to build Odoo connector with framework OCA/Connector.
- Clone repository from github
git clone https://github.com/hcmut-odoo/pospyt
import pospyt
from pprint import pprint
# Options to query data
filters = {
'price': {'operator': 'lt', 'value': 40000}
}
display = ['name', 'price', 'updated_at']
sort = {'price': 'asc'}
date = {
'start': '2021-10-20',
'end': '2021-11-20'
}
options = {
'filter':filters,
'display': display,
'sort': sort,
'limit': 2,
'date': date
}
-
In case using registed modules
# Get list of products by using registed modules resp = client.product.lits(options=options) pprint(resp)
id
is the default selected field in case we usedisplay
options. The result will be:[ { 'id': 23, 'name': 'Cà Phê Đen Đá', 'price': '32000.00', 'updated_at': '2021-11-11T15:09:29.000000Z' }, { 'id': 25, 'name': 'Cà Phê Sữa Đá', 'price': '32000.00', 'updated_at': '2021-11-11T15:09:29.000000Z' } ]
- Using arguments to compatible with the Odoo connector
In search method, list of ids is default result:
service = pospyt.PosWebServiceDict(BASE_URL, API_KEY) # Result of this way always return a dict or a list # Ids is a list of ids of user from pos website has type int/string ids = service.search('product/list', options=options) pprint(ids)
[25, 26]
You can find the source code in pospyt.py, and pospyt
have a timeout params in there.
Hence, every execute funtion can add an extra timeout setting, depending on your choice.
For example, we can set the timeout as 20 seconds in the execute requests(default value is 10s).
resp = client.user.list(per_page=40, page=2, timeout=20)
print(resp)
You can pass resource as argument instead of using registed modules. This way prefers to build the Odoo connector.
Example:
import pospyt
from pprint import pprint
service = pospyt.PosWebServiceDict(BASE_URL, API_KEY)
pprint(pos.search('user/list'))
Way to apply on Odoo connector:
class GenericAdapter(AbstractComponent):
_name = "pos.adapter"
_inherit = "pos.crud.adapter"
_model_name = None
_pos_model = None
_export_node_name = ""
_export_node_name_res = ""
@retryable_error
def search(self, filters=None):
"""Search records according to some criterias
and returns a list of ids
:rtype: list
"""
_logger.debug(
"method search, model %s, filters %s", self._pos_model, str(filters)
)
return self.client.search(self._pos_model, filters)
In this code, you can pass an resource
as _pos_model
to method search
.
Source code
https://github.com/hcmut-odoo/pospyt
Pos Documentation
https://github.com/hcmut-odoo/pos