Add new pricing system (#65)

This commit is contained in:
Fredrik Ringqvist
2023-05-05 10:33:02 +02:00
committed by GitHub
parent 1c5bcd4471
commit 4556155a84
5 changed files with 319 additions and 12 deletions
+77 -10
View File
@@ -15,6 +15,9 @@ from api.lib.prices import (
inquiry_price,
wallpaper_kit_price,
external_product_price,
wallpaper_price_new,
external_product_price_new,
inquiry_price_new,
)
mod = Blueprint("prices", __name__, url_prefix="/prices")
@@ -45,6 +48,8 @@ def wallpaper():
width = request.args.get("width", type=int)
height = request.args.get("height", type=int)
market_id = request.args.get("market", type=int)
product_id = request.args.get("product", type=int)
new_version = request.args.get("new_version") is not None
market = Market.query.get_or_404(market_id)
designer = get_designer()
reseller = get_reseller()
@@ -55,6 +60,20 @@ def wallpaper():
materials = Material.query.wallpapers().all()
data = []
for material in materials:
if new_version:
prices = wallpaper_price_new(product_id, width, height, material, market)
data.append(
{
"material": material.name,
"material_id": material.id,
"m2_price": prices["m2_price_incl_vat"],
"m2_price_excl_vat": prices["m2_price_excl_vat"],
"price": prices["incl_vat"],
"price_excl_vat": prices["excl_vat"],
}
)
continue
data.append(
{
"material": material.name,
@@ -139,7 +158,7 @@ def get_inquiry_measurements(inquiry):
return width, height
def inquiry_wallpaper(inquiry):
def inquiry_wallpaper(inquiry, new_version=False):
width, height = get_inquiry_measurements(inquiry)
data = {
@@ -152,6 +171,22 @@ def inquiry_wallpaper(inquiry):
materials = Material.query.wallpapers().all()
prices = []
for material in materials:
if new_version:
price = inquiry_price_new(inquiry, material=material, width=width, height=height)
prices.append(
{
"material": material.name,
"material_id": material.id,
"m2_price": price["m2_price_incl_vat"],
"m2_price_excl_vat": price["m2_price_excl_vat"],
"inquiry_price": price["incl_vat"],
"inquiry_price_excl_vat": price["excl_vat"],
"inquiry_price_excl_retouch": price["excl_retouch_incl_vat"],
"inquiry_price_excl_retouch_excl_vat": price["excl_retouch_excl_vat"],
}
)
continue
prices.append(
{
"material": material.name,
@@ -215,7 +250,24 @@ def inquiry_wallpaper(inquiry):
return data
def inquiry_external_product(inquiry, external_id):
def inquiry_external_product(inquiry, external_id, new_version):
if new_version:
result = inquiry_price_new(inquiry, external_id=external_id)
data = {
"id": inquiry.id,
# No manual inquiries for external products, hence no retouch price
"retouch_price": 0,
"prices": [
{
"inquiry_price": result["incl_vat"],
"inquiry_price_excl_vat": result["excl_vat"],
"inquiry_price_excl_retouch": result["incl_vat"],
"inquiry_price_excl_retouch_excl_vat": result["excl_vat"],
}
],
}
return data
data = {
"id": inquiry.id,
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
@@ -245,19 +297,20 @@ def inquiry(inquiry_id):
inquiry = Inquiry.query.get_or_404(inquiry_id)
external_product_id = request.args.get("external_product_id")
listprice = request.args.get("listprice")
new_version = request.args.get("new_version") is not None
if (listprice):
if (listprice == 'canvas'):
external_product_id = get_cheapest_canvas_product()
elif (listprice == 'poster'):
external_product_id = get_cheapest_poster_product()
if listprice:
if listprice == 'canvas':
external_product_id = get_cheapest_canvas_product(new_version)
elif listprice == 'poster':
external_product_id = get_cheapest_poster_product(new_version)
else:
raise ValueError("Invalid listprice group {}".format(listprice))
if external_product_id:
data = inquiry_external_product(inquiry, external_product_id)
data = inquiry_external_product(inquiry, external_product_id, new_version)
elif inquiry.product_group == "photo-wallpaper":
data = inquiry_wallpaper(inquiry)
data = inquiry_wallpaper(inquiry, new_version)
else:
raise ValueError("Invalid group {}".format(inquiry.product_group))
@@ -270,8 +323,22 @@ def inquiry(inquiry_id):
def external_product():
market_id = request.args.get("market", type=int)
market = Market.query.get_or_404(market_id)
designer = get_designer()
id = request.args.get("id", type=str)
new_version = request.args.get("new_version") is not None
if new_version:
product_id = request.args.get("product", type=int)
prices = external_product_price_new(product_id, id, market)
data = [
{
"id": id,
"price": prices["incl_vat"],
"price_excl_vat": prices['excl_vat']
}
]
return jsonify(data=data)
designer = get_designer()
data = [
{