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
+12 -3
View File
@@ -1,10 +1,15 @@
# coding=UTF-8
""" Price formulas """
from api.lib.utils import round_half_up
import yaml
from api.lib.utils import lru_with_ttl, round_half_up
from api.models.external_print_product import get_external_print_product
from api.models.price_adjustments import get_price_adjustment
@lru_with_ttl(ttl_seconds=3600)
def get_adjustment_config():
with open("api/resources/price-adjustments.yaml") as f:
return yaml.load(f, Loader=yaml.FullLoader)
def wallpaper_m2_price(
material,
market,
@@ -29,8 +34,12 @@ def wallpaper_m2_price(
price *= market.exchange_rate
price *= market.price_adjustments
adjustment_config = get_adjustment_config()
inquiry_or_product_key = "product" if inquiry is None else "inquiry"
price *= get_price_adjustment(market.name, material.name, inquiry_or_product_key)
adj_value = adjustment_config.get(material.name).get(inquiry_or_product_key).get(market.name, 1.0)
price *= adj_value
if inc_vat:
price *= market.vat