Files
tryton/modules/stock_package_shipping_mygls/api.py
T
Cédric Krier 74ee169c54 Refactor of trytond.config to add cache
This removes the need to store configuration in global variable and so make it
easier to update for example for testing.

Closes #14249
2025-10-07 08:19:57 +02:00

34 lines
1000 B
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import hashlib
from zeep import Client
from zeep.transports import Transport
import trytond.config as config
URLS = {
'testing': 'https://api.test.mygls.%(country)s/%(service)s.svc?singleWsdl',
'production': 'https://api.mygls.%(country)s/%(service)s.svc?singleWsdl',
}
def get_client(credential, service):
url = URLS[credential.server] % {
'country': credential.country,
'service': service,
}
timeout = config.get(
'stock_package_shipping_mygls', 'requests_timeout', default=300)
return Client(url, transport=Transport(operation_timeout=timeout))
def get_request(credential, name, **kwargs):
return {
name: {
'Username': credential.username,
'Password': hashlib.sha512(credential.password.encode()).digest(),
**kwargs,
},
}