Allow users to supply customer specific prices

fixes https://github.com/gsauthof/frank/issues/3
This commit is contained in:
Georg Sauthoff 2021-01-23 16:46:23 +01:00
parent 6c1f9bb1f5
commit 640baf1dbc
1 changed files with 10 additions and 5 deletions

View File

@ -25,16 +25,16 @@ _logger = logging.getLogger(__name__)
# This allows to ship multiple products.json files for announced future price/product # This allows to ship multiple products.json files for announced future price/product
# changes. # changes.
def load_products(): def load_products():
global marke_products
ps = [ e for e in resource_listdir(__name__, 'data') ps = [ e for e in resource_listdir(__name__, 'data')
if e.startswith('products-') and e.endswith('.json') if e.startswith('products-') and e.endswith('.json')
and e <= 'products-{}.json'.format(date.today().isoformat()) ] and e <= 'products-{}.json'.format(date.today().isoformat()) ]
ps.sort() ps.sort()
ps.insert(0, 'products.json') ps.insert(0, 'products.json')
products_json = resource_stream(__name__, 'data/' + ps[-1]).read().decode("utf-8") products_json = resource_stream(__name__, 'data/' + ps[-1]).read().decode("utf-8")
marke_products = json.loads(products_json) products = json.loads(products_json)
return products
load_products() default_products = load_products()
formats_json = resource_stream(__name__, "data/formats.json").read().decode("utf-8") formats_json = resource_stream(__name__, "data/formats.json").read().decode("utf-8")
formats = json.loads(formats_json) formats = json.loads(formats_json)
@ -94,16 +94,21 @@ class Internetmarke(object):
return [p, t, k, s] return [p, t, k, s]
def get_product_price_by_id(self, ext_prod_id): def get_product_price_by_id(self, ext_prod_id):
price_str = marke_products[str(ext_prod_id)]['cost_price'] price_str = self.products[str(ext_prod_id)]['cost_price']
return int(decimal.Decimal(price_str) * 100) return int(decimal.Decimal(price_str) * 100)
def __init__(self, partner_id, key, key_phase="1"): def __init__(self, partner_id, key, key_phase="1", products=None):
self.client = Client(self.wsdl_url) self.client = Client(self.wsdl_url)
self.partner_id = partner_id self.partner_id = partner_id
self.key_phase = key_phase self.key_phase = key_phase
self.key = key self.key = key
self.soapheader = self.gen_1c4a_hdr(self.partner_id, self.key_phase, self.key) self.soapheader = self.gen_1c4a_hdr(self.partner_id, self.key_phase, self.key)
self.positions = [] self.positions = []
if products is None:
self.products = default_products
else:
self.products = products
def authenticate(self, username, password): def authenticate(self, username, password):
s = self.client.service s = self.client.service