Revert "Remove listprice code and read price adjustments from database (#56)" (#57)

This reverts commit cdcefda954.
This commit is contained in:
Fredrik Ringqvist
2022-06-08 14:34:11 +02:00
committed by GitHub
parent cdcefda954
commit 292726e8c3
4 changed files with 83 additions and 39 deletions
-34
View File
@@ -1,34 +0,0 @@
# coding=UTF-8
from api.extensions import db
from api.lib.utils import lru_with_ttl
@lru_with_ttl(ttl_seconds=3600)
def get_adjustment_config():
sql = """
select
material, product_type, markets.name, price_adjustments.value
from
price_adjustments
join "product-materials" on material_id = materialid
join markets on market_id = markets.id
"""
result = db.session.execute(sql)
rows = result.fetchall()
config = {}
for row in rows:
[material, product_type, market, value] = row
if material not in config:
config[material] = {}
if product_type not in config[material]:
config[material][product_type] = {}
config[material][product_type][market] = float(value)
return config
def get_price_adjustment(market, product_type, material):
config = get_adjustment_config()
return config.get(material, {}).get(product_type, {}).get(market, 1.0)