# 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, material, product_type): config = get_adjustment_config() return config.get(material, {}).get(product_type, {}).get(market, 1.0)