Remove old routes and code (#52)

This commit is contained in:
Fredrik Ringqvist
2022-04-28 09:09:21 +02:00
committed by GitHub
parent 4a70102fdb
commit efccf49a37
8 changed files with 0 additions and 1452 deletions
-52
View File
@@ -1,52 +0,0 @@
# coding=UTF-8
CANVAS = {
"max_long_side": 500,
"min_long_side": 20,
"max_short_side": 150,
"min_short_side": 20,
}
CANVAS_FRAME = {
"max_long_side": 150,
"min_long_side": 40,
"max_short_side": 150,
"min_short_side": 40,
}
def calculate_canvas_frame_limits(width, height):
if width > height:
width = min(width, CANVAS_FRAME.get("max_long_side"))
width = max(width, CANVAS_FRAME.get("min_long_side"))
height = min(height, CANVAS_FRAME.get("max_short_side"))
height = max(height, CANVAS_FRAME.get("min_short_side"))
else:
height = min(height, CANVAS_FRAME.get("max_long_side"))
height = max(height, CANVAS_FRAME.get("min_long_side"))
width = min(width, CANVAS_FRAME.get("max_short_side"))
width = max(width, CANVAS_FRAME.get("min_short_side"))
# round to nearest 10
width = round(width, -1)
height = round(height, -1)
return width, height
def calculate_canvas_limits(width, height, framed=False):
if framed:
return calculate_canvas_frame_limits(width, height)
if width > height:
width = min(width, CANVAS.get("max_long_side"))
width = max(width, CANVAS.get("min_long_side"))
height = min(height, CANVAS.get("max_short_side"))
height = max(height, CANVAS.get("min_short_side"))
else:
height = min(height, CANVAS.get("max_long_side"))
height = max(height, CANVAS.get("min_long_side"))
width = min(width, CANVAS.get("max_short_side"))
width = max(width, CANVAS.get("min_short_side"))
return width, height
-401
View File
@@ -2,8 +2,6 @@
""" Price formulas """ """ Price formulas """
from api.lib.utils import round_half_up from api.lib.utils import round_half_up
from api.lib.limits import calculate_canvas_limits
from api.lib import pwinty
from api.models.external_print_product import get_external_print_product from api.models.external_print_product import get_external_print_product
@@ -75,229 +73,6 @@ def wallpaper_price(
return price return price
def canvas_cm2_price(cm2):
price_cm2_at_1cm2 = 0.2461
price_cm2_at_5000cm2 = 0.144
price_cm2_at_10000cm2 = 0.096
price_cm2_at_22500cm2 = 0.064
if cm2 <= 5000:
diff = price_cm2_at_1cm2 - price_cm2_at_5000cm2
discount = (diff / 5000) * cm2
cm2_price = price_cm2_at_1cm2 - discount
elif cm2 > 5000 and cm2 <= 10000:
diff = price_cm2_at_5000cm2 - price_cm2_at_10000cm2
discount = (diff / 5000) * (cm2 - 5000)
cm2_price = price_cm2_at_5000cm2 - discount
elif cm2 > 10000:
diff = price_cm2_at_10000cm2 - price_cm2_at_22500cm2
discount = (diff / 12500) * (cm2 - 10000)
cm2_price = price_cm2_at_10000cm2 - discount
cm2_price = max(cm2_price, 0.064)
return cm2_price
def package_price(product_group, width, height, market):
if market.name == "US":
if product_group in ["canvas", "poster"]:
if width > 110:
return 150
else:
return 100
return 0
def canvas_price(
width,
height,
market,
framed=True,
designer=None,
reseller=None,
inquiry=None,
rounded=True,
inc_vat=True,
):
cm2 = width * height
cm2_price = canvas_cm2_price(cm2)
# calculate price for canvas with frame
price = cm2 * cm2_price
price = max(price, 341.4848) # the price can never go below 341.4848 SEK
if not framed:
price *= 0.7
price *= market.price_adjustments
if designer:
price *= (float(designer.pricepremium_canvas) / 100) + 1
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
if inquiry:
price *= (float(inquiry.pricepremium) / 100) + 1
price += package_price("canvas", width, height, market)
price *= market.exchange_rate
if inc_vat:
price *= market.vat
if rounded:
price = round_half_up(price)
return price
def canvas_frame_price(
width, height, market, reseller=None, rounded=True, inc_vat=True
):
width, height = calculate_canvas_limits(width, height, framed=True)
cm2 = width * height
cm2_price = canvas_cm2_price(cm2)
price = cm2 * cm2_price
price = max(price, 317.44)
price *= 0.65
price *= market.price_adjustments
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
price += package_price("canvas", width, height, market)
price *= market.exchange_rate
if inc_vat:
price *= market.vat
if rounded:
price = round_half_up(price)
return price
def poster_cm2_price(cm2):
price_cm2_at_1cm2 = 0.1008
price_cm2_at_5000cm2 = 0.04704
price_cm2_at_10000cm2 = 0.04032
price_cm2_at_22500cm2 = 0.0336
if cm2 <= 5000:
diff = price_cm2_at_1cm2 - price_cm2_at_5000cm2
discount = (diff / 5000) * cm2
cm2_price = price_cm2_at_1cm2 - discount
elif cm2 > 5000 and cm2 <= 10000:
diff = price_cm2_at_5000cm2 - price_cm2_at_10000cm2
discount = (diff / 5000) * (cm2 - 5000)
cm2_price = price_cm2_at_5000cm2 - discount
elif cm2 > 10000:
diff = price_cm2_at_10000cm2 - price_cm2_at_22500cm2
discount = (diff / 12500) * (cm2 - 10000)
cm2_price = price_cm2_at_10000cm2 - discount
cm2_price = max(cm2_price, 0.028)
return cm2_price
def poster_price(
width,
height,
market,
hanger=True,
designer=None,
reseller=None,
inquiry=None,
rounded=True,
inc_vat=True,
):
cm2 = width * height
cm2_price = poster_cm2_price(cm2)
price = cm2 * cm2_price
price = max(price, 200) # the price can never go below 200 SEK
if hanger:
price += _price_for_poster_hanger_size(width)
price *= market.price_adjustments
if designer:
price *= (float(designer.pricepremium_poster) / 100) + 1
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
if inquiry:
price *= (float(inquiry.pricepremium) / 100) + 1
price += package_price("poster", width, height, market)
price *= market.exchange_rate
if inc_vat:
price *= market.vat
if rounded:
price = round_half_up(price)
return price
def poster_hanger_price(width, market, reseller=None, rounded=True, inc_vat=True):
"""calculates price for poster hanger only"""
price = _price_for_poster_hanger_size(width)
price += 50 # add 50 SEK extra since they are buying only the hanger
price *= market.price_adjustments
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
price += package_price(
"poster", width, 10, market
) # we assume the poster hanger has a height of 10cm here
price *= market.exchange_rate
if inc_vat:
price *= market.vat
if rounded:
price = round_half_up(price)
return price
def _price_for_poster_hanger_size(size):
if size > 0 and size <= 30:
return 83
if size > 30 and size <= 50:
return 118
if size > 50 and size <= 60:
return 125
if size > 60 and size <= 70:
return 132
if size > 70 and size <= 100:
return 192
if size > 100 and size <= 125:
return 218
if size > 125 and size <= 150:
return 262
raise ValueError("Invalid poster hanger size: {}".format(size))
def _designer_pricepremium(designer, group_id): def _designer_pricepremium(designer, group_id):
if group_id in [1,3,6]: if group_id in [1,3,6]:
return designer.pricepremium_wallpaper return designer.pricepremium_wallpaper
@@ -337,153 +112,12 @@ def external_product_price(
return price return price
def framed_print_price(
sku, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True
):
sku_prices = {
pwinty.GLOBAL_CFP_12x12: 446,
pwinty.GLOBAL_CFP_11x14: 478,
pwinty.GLOBAL_CFP_12x16: 494,
pwinty.GLOBAL_CFP_16x20: 574,
pwinty.GLOBAL_CFP_20x20: 690,
pwinty.GLOBAL_CFP_18x24: 708,
pwinty.GLOBAL_CFP_20x28: 761,
pwinty.GLOBAL_CFP_24x32: 831,
pwinty.GLOBAL_CFP_28x28: 867,
pwinty.GLOBAL_CFP_24x36: 1035,
pwinty.GLOBAL_CFP_28x40: 1127,
}
if not sku in sku_prices:
raise ValueError("Invalid SKU number: {}".format(sku))
price = sku_prices[sku]
# add extra shipping price (in SEK)
extra_shipping_price = {
pwinty.GLOBAL_CFP_11x14: { # 28x36
"US": 167,
"NO": 247,
"FI": 85,
"PL": 102,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_12x16: { # 30x40
"US": 167,
"NO": 247,
"FI": 85,
"PL": 102,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_16x20: { # 40x50
"US": 243,
"NO": 247,
"FI": 85,
"PL": 123,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_18x24: { # 45x60
"US": 243,
"NO": 247,
"FI": 85,
"PL": 139,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_20x28: { # 50x70
"US": 472,
"NO": 371,
"FI": 85,
"PL": 150,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_24x32: { # 60x80
"US": 472,
"NO": 371,
"FI": 85,
"PL": 160,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_24x36: { # 60x90
"US": 510,
"NO": 989,
"FI": 85,
"PL": 196,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_28x40: { # 70x100
"US": 510,
"NO": 989,
"FI": 85,
"PL": 211,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_12x12: { # 30x30
"US": 167,
"NO": 247,
"FI": 85,
"PL": 102,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_20x20: { # 50x50
"US": 243,
"NO": 247,
"FI": 85,
"PL": 123,
"ES": 63,
"SE": 32,
},
pwinty.GLOBAL_CFP_28x28: { # 70x70
"US": 472,
"NO": 371,
"FI": 85,
"PL": 150,
"ES": 63,
"SE": 32,
},
}
price += extra_shipping_price[sku].get(market.name, 0)
price *= market.price_adjustments
if designer:
price *= (float(designer.pricepremium_framed_print) / 100) + 1
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
if inquiry:
price *= (float(inquiry.pricepremium) / 100) + 1
price *= market.exchange_rate
if inc_vat:
price *= market.vat
if rounded:
price = round_half_up(price)
return price
def inquiry_price( def inquiry_price(
inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs
): ):
width = kwargs.get("width", inquiry.width) width = kwargs.get("width", inquiry.width)
height = kwargs.get("height", inquiry.height) height = kwargs.get("height", inquiry.height)
material = kwargs.get("material", inquiry.material) material = kwargs.get("material", inquiry.material)
framed = kwargs.get("framed", inquiry.framed)
hanger = kwargs.get("hanger", inquiry.hanger)
sku = kwargs.get("sku")
reseller = kwargs.get("reseller", inquiry.dealer_store) reseller = kwargs.get("reseller", inquiry.dealer_store)
external_id = kwargs.get("external_id") external_id = kwargs.get("external_id")
@@ -508,41 +142,6 @@ def inquiry_price(
rounded=False, rounded=False,
inc_vat=False, inc_vat=False,
) )
elif inquiry.product_group == "canvas":
price = canvas_price(
width,
height,
inquiry.market,
designer=inquiry.designer,
reseller=reseller,
inquiry=inquiry,
framed=framed,
rounded=False,
inc_vat=False,
)
elif inquiry.product_group == "poster" and not sku:
price = poster_price(
width,
height,
inquiry.market,
designer=inquiry.designer,
reseller=reseller,
inquiry=inquiry,
hanger=hanger,
rounded=False,
inc_vat=False,
)
# Framed prints product group for inquires will be poster until addToCart but always has sku
elif sku:
price = framed_print_price(
sku=sku,
market=inquiry.market,
designer=inquiry.designer,
reseller=reseller,
inquiry=inquiry,
rounded=False,
inc_vat=False,
)
else: else:
raise ValueError("Invalid product group: {}".format(inquiry.product_group)) raise ValueError("Invalid product group: {}".format(inquiry.product_group))
-25
View File
@@ -1,25 +0,0 @@
GLOBAL_CFP_12x12 = "GLOBAL-CFP-12x12"
GLOBAL_CFP_11x14 = "GLOBAL-CFP-11x14"
GLOBAL_CFP_12x16 = "GLOBAL-CFP-12x16"
GLOBAL_CFP_16x20 = "GLOBAL-CFP-16x20"
GLOBAL_CFP_20x20 = "GLOBAL-CFP-20x20"
GLOBAL_CFP_18x24 = "GLOBAL-CFP-18x24"
GLOBAL_CFP_20x28 = "GLOBAL-CFP-20x28"
GLOBAL_CFP_24x32 = "GLOBAL-CFP-24x32"
GLOBAL_CFP_28x28 = "GLOBAL-CFP-28x28"
GLOBAL_CFP_24x36 = "GLOBAL-CFP-24x36"
GLOBAL_CFP_28x40 = "GLOBAL-CFP-28x40"
SKU_CODES = [
GLOBAL_CFP_12x12,
GLOBAL_CFP_11x14,
GLOBAL_CFP_12x16,
GLOBAL_CFP_16x20,
GLOBAL_CFP_20x20,
GLOBAL_CFP_18x24,
GLOBAL_CFP_20x28,
GLOBAL_CFP_24x32,
GLOBAL_CFP_28x28,
GLOBAL_CFP_24x36,
GLOBAL_CFP_28x40,
]
-427
View File
@@ -10,20 +10,13 @@ from api.models import (
PrintProduct, PrintProduct,
ContractCustomer, ContractCustomer,
) )
from api.lib import pwinty
from api.lib.prices import ( from api.lib.prices import (
wallpaper_price, wallpaper_price,
canvas_price,
canvas_frame_price,
poster_price,
poster_hanger_price,
framed_print_price,
wallpaper_m2_price, wallpaper_m2_price,
inquiry_price, inquiry_price,
wallpaper_kit_price, wallpaper_kit_price,
external_product_price, external_product_price,
) )
from api.lib.limits import calculate_canvas_limits
mod = Blueprint("prices", __name__, url_prefix="/prices") mod = Blueprint("prices", __name__, url_prefix="/prices")
mod.before_request(check_api_key) mod.before_request(check_api_key)
@@ -106,129 +99,6 @@ def wallpaper():
return jsonify(data=data) return jsonify(data=data)
@mod.route("/canvas", methods=["GET"])
@validate_number("width", "height")
@validate_exists("market")
def canvas():
market_id = request.args.get("market", type=int)
market = Market.query.get_or_404(market_id)
reseller = get_reseller()
designer = get_designer()
data = []
for framed in [True, False]:
width, height = calculate_canvas_limits(
request.args.get("width", type=int),
request.args.get("height", type=int),
framed,
)
data.append(
{
"framed": framed,
"width": width,
"height": height,
"price": canvas_price(
width,
height,
market,
framed=framed,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=True,
),
"price_excl_vat": canvas_price(
width,
height,
market,
framed=framed,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=False,
),
}
)
return jsonify(data=data)
@mod.route("/poster", methods=["GET"])
@validate_number("width", "height")
@validate_exists("market")
def poster():
market_id = request.args.get("market", type=int)
width = request.args.get("width", type=int)
height = request.args.get("height", type=int)
market = Market.query.get_or_404(market_id)
reseller = get_reseller()
designer = get_designer()
data = []
for hanger in [True, False]:
data.append(
{
"hanger": hanger,
"width": width,
"height": height,
"price": poster_price(
width,
height,
market,
hanger=hanger,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=True,
),
"price_excl_vat": poster_price(
width,
height,
market,
hanger=hanger,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=False,
),
}
)
return jsonify(data=data)
@mod.route("/diy-frame", methods=["GET"])
@validate_number("width", "height")
@validate_exists("market")
def diy_frame():
market_id = request.args.get("market", type=int)
market = Market.query.get_or_404(market_id)
reseller = get_reseller()
width, height = calculate_canvas_limits(
request.args.get("width", type=int),
request.args.get("height", type=int),
framed=True,
)
data = [
{
"width": width,
"height": height,
"price": canvas_frame_price(
width, height, market, reseller=reseller, rounded=False
),
"price_excl_vat": canvas_frame_price(
width, height, market, reseller=reseller, rounded=False, inc_vat=False
),
}
]
return jsonify(data=data)
@mod.route("/wallpaper-kit", methods=["GET"]) @mod.route("/wallpaper-kit", methods=["GET"])
@validate_exists("market") @validate_exists("market")
def wallpaper_kit(): def wallpaper_kit():
@@ -248,65 +118,6 @@ def wallpaper_kit():
return jsonify(data=data) return jsonify(data=data)
@mod.route("/poster-hanger", methods=["GET"])
@validate_number("width")
@validate_exists("market")
def poster_hanger():
market_id = request.args.get("market", type=int)
width = request.args.get("width", type=int)
market = Market.query.get_or_404(market_id)
reseller = get_reseller()
data = [
{
"width": width,
"price": poster_hanger_price(
width, market, reseller=reseller, rounded=False
),
"price_excl_vat": poster_hanger_price(
width, market, reseller=reseller, rounded=False, inc_vat=False
),
}
]
return jsonify(data=data)
@mod.route("/framed-print", methods=["GET"])
@validate_any_of("sku", pwinty.SKU_CODES)
@validate_exists("market")
def framed_print():
market_id = request.args.get("market", type=int)
sku = request.args.get("sku", type=str)
market = Market.query.get_or_404(market_id)
reseller = get_reseller()
designer = get_designer()
data = [
{
"sku": sku,
"price": framed_print_price(
sku,
market,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=True,
),
"price_excl_vat": framed_print_price(
sku,
market,
designer=designer,
reseller=reseller,
rounded=False,
inc_vat=False,
),
}
]
return jsonify(data=data)
def get_inquiry_measurements(inquiry): def get_inquiry_measurements(inquiry):
""" this function returns width and height to be used in the price calculations """ """ this function returns width and height to be used in the price calculations """
@@ -402,130 +213,6 @@ def inquiry_wallpaper(inquiry):
return data return data
def inquiry_canvas(inquiry):
in_width, in_height = get_inquiry_measurements(inquiry)
data = {
"id": inquiry.id,
"group": "canvas",
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
}
material = Material.query.canvas().first()
prices = []
for framed in [True, False]:
width, height = calculate_canvas_limits(in_width, in_height, framed)
prices.append(
{
"framed": framed,
"width": width,
"height": height,
"inquiry_price_excl_retouch": inquiry_price(
inquiry,
material=material,
width=width,
height=height,
framed=framed,
rounded=False,
inc_price_retouch=False,
inc_vat=True,
),
"inquiry_price": inquiry_price(
inquiry,
material=material,
width=width,
height=height,
framed=framed,
rounded=False,
inc_vat=True,
),
"inquiry_price_excl_vat": inquiry_price(
inquiry,
material=material,
width=width,
height=height,
framed=framed,
rounded=False,
inc_vat=False,
),
"inquiry_price_excl_price_premium": inquiry_price(
inquiry,
material=material,
width=width,
height=height,
reseller=None,
inc_price_retouch=False,
framed=framed,
rounded=False,
inc_vat=False,
),
}
)
data["prices"] = prices
return data
def inquiry_poster(inquiry):
width, height = get_inquiry_measurements(inquiry)
data = {
"id": inquiry.id,
"group": "poster",
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
}
prices = []
for hanger in [True, False]:
prices.append(
{
"hanger": hanger,
"width": width,
"height": height,
"inquiry_price_excl_retouch": inquiry_price(
inquiry,
width=width,
height=height,
hanger=hanger,
rounded=False,
inc_price_retouch=False,
inc_vat=True,
),
"inquiry_price": inquiry_price(
inquiry,
width=width,
height=height,
hanger=hanger,
rounded=False,
inc_vat=True,
),
"inquiry_price_excl_vat": inquiry_price(
inquiry,
width=width,
height=height,
hanger=hanger,
rounded=False,
inc_vat=False,
),
"inquiry_price_excl_price_premium": inquiry_price(
inquiry,
width=width,
height=height,
hanger=hanger,
reseller=None,
inc_price_retouch=False,
rounded=False,
inc_vat=False,
),
}
)
data["prices"] = prices
return data
def inquiry_external_product(inquiry, external_id): def inquiry_external_product(inquiry, external_id):
data = { data = {
"id": inquiry.id, "id": inquiry.id,
@@ -551,47 +238,10 @@ def inquiry_external_product(inquiry, external_id):
return data return data
def inquiry_framed_print(inquiry):
sku = request.args.get("sku", type=str)
data = {
"id": inquiry.id,
"group": "framed-print",
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
"prices": [
{
"inquiry_price_excl_retouch": inquiry_price(
inquiry,
sku=sku,
rounded=False,
inc_price_retouch=False,
inc_vat=True,
),
"inquiry_price": inquiry_price(
inquiry, sku=sku, rounded=False, inc_vat=True
),
"inquiry_price_excl_vat": inquiry_price(
inquiry, sku=sku, rounded=False, inc_vat=False
),
"inquiry_price_excl_price_premium": inquiry_price(
inquiry,
sku=sku,
reseller=None,
inc_price_retouch=False,
rounded=False,
inc_vat=False,
),
}
],
}
return data
@mod.route("/inquiry/<int:inquiry_id>", methods=["GET"]) @mod.route("/inquiry/<int:inquiry_id>", methods=["GET"])
def inquiry(inquiry_id): def inquiry(inquiry_id):
inquiry = Inquiry.query.get_or_404(inquiry_id) inquiry = Inquiry.query.get_or_404(inquiry_id)
external_product_id = request.args.get("external_product_id") external_product_id = request.args.get("external_product_id")
sku = request.args.get("sku", type=str)
listprice = request.args.get("listprice") listprice = request.args.get("listprice")
if (listprice): if (listprice):
@@ -606,12 +256,6 @@ def inquiry(inquiry_id):
data = inquiry_external_product(inquiry, external_product_id) data = inquiry_external_product(inquiry, external_product_id)
elif inquiry.product_group == "photo-wallpaper": elif inquiry.product_group == "photo-wallpaper":
data = inquiry_wallpaper(inquiry) data = inquiry_wallpaper(inquiry)
elif inquiry.product_group == "canvas":
data = inquiry_canvas(inquiry)
elif inquiry.product_group == "poster" and not sku:
data = inquiry_poster(inquiry)
elif sku:
data = inquiry_framed_print(inquiry)
else: else:
raise ValueError("Invalid group {}".format(inquiry.product_group)) raise ValueError("Invalid group {}".format(inquiry.product_group))
@@ -666,77 +310,6 @@ def list_prices_poster_external(market_id):
return jsonify(result) return jsonify(result)
@mod.route("/list-prices/<int:market_id>/canvas")
def list_prices_canvas(market_id):
canvases = PrintProduct.query.canvases().all()
market = Market.query.get_or_404(market_id)
result = {}
for canvas in canvases:
result[canvas.id] = canvas_price(
width=40,
height=40,
market=market,
framed=True,
designer=canvas.product.designer,
)
return jsonify(result)
@mod.route("/list-prices/<int:market_id>/poster")
def list_prices_posters(market_id):
posters = PrintProduct.query.posters().all()
market = Market.query.get_or_404(market_id)
result = {}
for poster in posters:
result[poster.id] = poster_price(
width=30,
height=30,
market=market,
hanger=False,
designer=poster.product.designer,
)
return jsonify(result)
@mod.route("/list-prices/<int:market_id>/framed-print")
def list_prices_framed_prints(market_id):
from api.extensions import db
from types import SimpleNamespace
query = (
"SELECT prints.printid, designers.pricepremium_framed_print, "
'width.value AS width, height.value AS height FROM "product-printproducts" prints '
'JOIN "product-products" products ON prints.productid = products.productid '
'LEFT JOIN "product-products_fields" width ON width.fieldid = 5 and width.productid = products.productid '
'LEFT JOIN "product-products_fields" height ON height.fieldid = 3 and height.productid = products.productid '
"LEFT JOIN designers ON designers.designerid = products.designerid "
"WHERE prints.groupid = :group"
)
rows = db.session.execute(query, {"group": 8})
market = Market.query.get_or_404(market_id)
result = {}
for row in rows:
printid, pricepremium_framed_print, width, height = row
if not pricepremium_framed_print:
pricepremium_framed_print = 0
designer = SimpleNamespace(pricepremium_framed_print=pricepremium_framed_print)
if width == height:
sku = pwinty.GLOBAL_CFP_12x12
else:
sku = pwinty.GLOBAL_CFP_11x14
result[printid] = framed_print_price(sku=sku, market=market, designer=designer)
return jsonify(result)
@mod.route("/external-product", methods=["GET"]) @mod.route("/external-product", methods=["GET"])
@validate_exists("market") @validate_exists("market")
@validate_exists("id") @validate_exists("id")
-164
View File
@@ -43,114 +43,6 @@ Sample response
} }
``` ```
## Calculate canvas price
Calculate price inc VAT of a canvas product. The response will contain information for both framed/not framed canvases. Note that width and height parameters may be adjusted if they go over or under the limits that are valid for a canvas. The values that are used in the price-calculation are always returned in the response.
| Parameter | Description |
| --------- | ------------|
| `width` | Canvas width in cm e.g `100` |
| `height` | Canvas height in cm e.g `50` |
| `market` | Market id e.g `1` for sweden. Markets affect the price in different ways like VAT, currency exchanges etc. |
| `dealerurl` | Optional parameter e.g `ackes`. Should always be used when calling the api from a dealerstore. If a dealerstore exists with this url additional fees will be applied to the price. |
| `product` | Optional parameter e.g `43894`. If a product with this id exists the api will calculate the price for the given product. |
Sample request
`curl -X GET 'https://api.photowall.com/prices/canvas?width=100&height=50&market=14`
Sample response
```
{
"data": [
{
"framed": true,
"height": 50,
"m2_price": 252.37137599999997,
"m2_price_excl_vat": 201.89710079999998,
"price": 224.92771680815997,
"price_excl_vat": 179.942173446528,
"width": 100
},
{
"framed": false,
"height": 50,
"m2_price": 252.37137599999997,
"m2_price_excl_vat": 201.89710079999998,
"price": 126.18568799999998,
"price_excl_vat": 100.94855039999999,
"width": 100
}
]
}
```
## Calculate poster price
Calculate price inc VAT of a poster product. The response will contain prices for both with and without hanger.
| Parameter | Description |
| --------- | ------------|
| `width` | Poster width in cm e.g `100` |
| `height` | Poster height in cm e.g `50` |
| `market` | Market id e.g `1` for sweden. Markets affect the price in different ways like VAT, currency exchanges etc. |
| `dealerurl` | Optional parameter e.g `ackes`. Should always be used when calling the api from a dealerstore. If a dealerstore exists with this url additional fees will be applied to the price. |
| `product` | Optional parameter e.g `43894`. If a product with this id exists the api will calculate the price for the given product. |
Sample request
`curl -X GET 'https://api.photowall.com/prices/poster?width=50&height=30&market=1&product=46654`
Sample response
```
{
"data": [
{
"hanger": true,
"height": 30,
"price": 401.03000000000003,
"price_excl_vat": 320.824,
"width": 50
},
{
"hanger": false,
"height": 30,
"price": 199.92000000000002,
"price_excl_vat": 159.936,
"width": 50
}
]
}
```
## Calculate framed print price
Calculate price inc VAT of a framed print product.
| Parameter | Description |
| --------- | ------------|
| `sku` | Pwinty SKU number |
| `market` | Market id e.g `1` for sweden. Markets affect the price in different ways like VAT, currency exchanges etc. |
| `dealerurl` | Optional parameter e.g `ackes`. Should always be used when calling the api from a dealerstore. If a dealerstore exists with this url additional fees will be applied to the price. |
| `product` | Optional parameter e.g `43894`. If a product with this id exists the api will calculate the price for the given product. |
Sample request
`curl -X GET 'https://api.photowall.com/prices/framed-print?sku=GLOBAL-CFP-12x12&market=1`
Sample response
```
{
"data": [
{
"price": 557.5,
"price_excl_vat": 446.0,
"sku": "GLOBAL-CFP-12x12"
}
]
}
```
## Calculate external product price ## Calculate external product price
@@ -179,62 +71,6 @@ Sample response
} }
``` ```
## Calculate "Do it yourself frame" price
Calculate the price for the "do it yourself frame" (DIY). Note that width and height parameters may be adjusted if they go over or under the limits that are valid for a canvas-frame. The values that are used in the price-calculation are always returned in the response.
| Parameter | Description |
| --------- | ------------|
| `width` | Canvas width in cm e.g `100` |
| `height` | Canvas height in cm e.g `50` |
| `market` | Market id e.g `1` for sweden. Markets affect the price in different ways like VAT, currency exchanges etc. |
| `dealerurl` | Optional parameter e.g `ackes`. Should always be used when calling the api from a dealerstore. If a dealerstore exists with this url additional fees will be applied to the price. |
Sample request
`curl -X GET 'https://api.photowall.com/prices/diy-frame?width=150&height=150&market=1`
Sample response
```
{
"data": [
{
"height": 150,
"price": 1327,
"width": 150
}
]
}
```
## Calculate Poster hanger price
Calculate the price for a poster hanger
| Parameter | Description |
| --------- | ------------|
| `width` | Poster hanger width in cm e.g `100` |
| `market` | Market id e.g `1` for sweden. Markets affect the price in different ways like VAT, currency exchanges etc. |
| `dealerurl` | Optional parameter e.g `ackes`. Should always be used when calling the api from a dealerstore. If a dealerstore exists with this url additional fees will be applied to the price. |
Sample request
`curl -X GET 'https://api.photowall.com/prices/poster-hanger?width=50&market=1`
Sample response
```
{
"data": [
{
"price": 231.5,
"price_excl_vat": 185.2,
"width": 50
}
]
}
```
## Calculate inquiry price ## Calculate inquiry price
-24
View File
@@ -1,24 +0,0 @@
# coding=UTF-8
import unittest2
from api.lib.limits import calculate_canvas_limits, calculate_canvas_frame_limits
class TestCalculate(unittest2.TestCase):
def test_calculate_canvas_limits(self):
self.assertEqual((100, 100), calculate_canvas_limits(100, 100))
self.assertEqual((500, 100), calculate_canvas_limits(800, 100))
self.assertEqual((100, 500), calculate_canvas_limits(100, 800))
self.assertEqual((20, 20), calculate_canvas_limits(10, 10))
self.assertEqual(
(150, 50), calculate_canvas_limits(400, 50, True), "Framed canvas"
)
def test_calculate_canvas_frame_limits(self):
self.assertEqual((100, 100), calculate_canvas_frame_limits(100, 100))
self.assertEqual((40, 40), calculate_canvas_frame_limits(1, 1))
self.assertEqual((150, 150), calculate_canvas_frame_limits(200, 200))
self.assertEqual((150, 40), calculate_canvas_frame_limits(200, 10))
self.assertEqual(
(110, 120), calculate_canvas_frame_limits(112, 117), "round to nearest 10"
)
-237
View File
@@ -186,147 +186,6 @@ class TestPrice(unittest2.TestCase):
"Minium price for US is 2 sqm", "Minium price for US is 2 sqm",
) )
def test_canvas_cm2_price(self):
self.assertEqual(0.24099500000000001, canvas_cm2_price(250))
self.assertEqual(0.24589580000000003, canvas_cm2_price(10))
self.assertEqual(0.22568000000000002, canvas_cm2_price(1000))
def test_canvas_price(self):
self.assertEqual(
488,
canvas_price(
width=50, height=50, market=sweden, framed=True, inc_vat=False
),
)
self.assertEqual(
960,
canvas_price(
width=100, height=100, market=sweden, framed=True, inc_vat=False
),
)
self.assertEqual(
1359,
canvas_price(
width=150, height=120, market=sweden, framed=True, inc_vat=False
),
)
self.assertEqual(
256000,
canvas_price(
width=2000, height=2000, market=sweden, framed=True, inc_vat=False
),
)
self.assertEqual(
341,
canvas_price(
width=10, height=10, market=sweden, framed=True, inc_vat=False
),
)
self.assertEqual(
427,
canvas_price(width=40, height=40, market=sweden, framed=True, inc_vat=True),
)
self.assertEqual(
299,
canvas_price(
width=40, height=40, market=sweden, framed=False, inc_vat=True
),
)
self.assertEqual(
731,
canvas_price(
width=80, height=80, market=sweden, framed=False, inc_vat=True
),
)
self.assertEqual(
1044,
canvas_price(width=80, height=80, market=sweden, framed=True, inc_vat=True),
)
self.assertEqual(
1260,
canvas_price(
width=150, height=150, market=sweden, framed=False, inc_vat=True
),
)
self.assertEqual(
1800,
canvas_price(
width=150, height=150, market=sweden, framed=True, inc_vat=True
),
)
self.assertEqual(
201,
canvas_price(width=150, height=150, market=us, framed=True, inc_vat=True),
)
self.assertEqual(
672,
canvas_price(
width=100, height=100, market=sweden, framed=False, inc_vat=False
),
)
self.assertEqual(
840,
canvas_price(
width=100, height=100, market=sweden, framed=False, inc_vat=True
),
)
self.assertEqual(
462,
canvas_price(
width=50, height=50, market=denmark, framed=True, inc_vat=False
),
)
self.assertEqual(
181,
canvas_price(
width=150,
height=100,
market=us,
designer=designer_moomin,
inc_vat=False,
),
)
self.assertEqual(
181,
canvas_price(
width=150, height=100, market=us, designer=designer_moomin, inc_vat=True
),
)
def test_canvas_frame_price(self):
self.assertEqual(
624, canvas_frame_price(width=100, height=100, market=sweden, inc_vat=False)
)
self.assertEqual(
780, canvas_frame_price(width=100, height=100, market=sweden, inc_vat=True)
)
self.assertEqual(88, canvas_frame_price(width=100, height=100, market=eu))
self.assertEqual(
936, canvas_frame_price(500, 500, market=sweden, inc_vat=False)
)
self.assertEqual(222, canvas_frame_price(1, 1, market=sweden, inc_vat=False))
self.assertEqual(
277, canvas_frame_price(width=40, height=40, market=sweden, inc_vat=True)
)
self.assertEqual(71, canvas_frame_price(width=40, height=120, market=us))
self.assertEqual(66, canvas_frame_price(width=40, height=100, market=us))
self.assertEqual(578, canvas_frame_price(width=40, height=120, market=sweden))
def test_wallpaper_custom_inquiry_price(self): def test_wallpaper_custom_inquiry_price(self):
with mock.patch.object(Inquiry, "market", nl): with mock.patch.object(Inquiry, "market", nl):
inquiry = Inquiry( inquiry = Inquiry(
@@ -396,102 +255,6 @@ class TestPrice(unittest2.TestCase):
250, inquiry.local_price_retouch(rounded=True, inc_vat=True) 250, inquiry.local_price_retouch(rounded=True, inc_vat=True)
) )
def test_canvas_custom_inquiry_price(self):
with mock.patch.object(Inquiry, "market", sweden):
inquiry = Inquiry(
product_group="canvas",
width=100,
height=100,
framed=True,
price_retouch=200,
pricepremium=0,
material=standard_canvas,
)
self.assertEqual(1200, inquiry_price(inquiry, inc_price_retouch=False))
self.assertEqual(1450, inquiry_price(inquiry, inc_price_retouch=True))
self.assertEqual(
840, inquiry_price(inquiry, inc_price_retouch=False, framed=False)
)
def test_package_price(self):
self.assertEqual(150, package_price("canvas", 150, 40, market=us))
self.assertEqual(0, package_price("canvas", 150, 40, market=sweden))
self.assertEqual(150, package_price("poster", 150, 40, market=us))
self.assertEqual(100, package_price("poster", 40, 40, market=us))
self.assertEqual(0, package_price("poster", 150, 40, market=sweden))
def test_poster_cm2_price(self):
self.assertEqual(0.100789248, poster_cm2_price(1))
self.assertEqual(0.0997248, poster_cm2_price(100))
self.assertEqual(0.090048, poster_cm2_price(1000))
self.assertEqual(0.04032, poster_cm2_price(10000))
self.assertEqual(0.028, poster_cm2_price(100000))
def test_poster_price(self):
self.assertEqual(
354, poster_price(width=30, height=40, hanger=True, market=sweden)
)
self.assertEqual(
250, poster_price(width=30, height=40, hanger=False, market=sweden)
)
self.assertEqual(
48,
poster_price(width=30, height=40, hanger=True, market=us),
"extra cost for us market",
)
self.assertEqual(
76,
poster_price(width=120, height=40, market=us),
"high extra cost for us market wide posters",
)
self.assertEqual(
78, poster_price(width=120, height=40, market=us, designer=designer_moomin)
)
def test_poster_hanger_price(self):
self.assertEqual(166, poster_hanger_price(30, market=sweden))
self.assertEqual(390, poster_hanger_price(150, market=sweden))
self.assertEqual(29, poster_hanger_price(30, market=us))
self.assertEqual(58, poster_hanger_price(150, market=us))
def test_poster_custom_inquiry_price(self):
with mock.patch.object(Inquiry, "market", sweden):
inquiry = Inquiry(
product_group="poster",
width=30,
height=40,
hanger=True,
price_retouch=200,
pricepremium=0,
)
self.assertEqual(354, inquiry_price(inquiry, inc_price_retouch=False))
self.assertEqual(604, inquiry_price(inquiry, inc_price_retouch=True))
self.assertEqual(
250, inquiry_price(inquiry, inc_price_retouch=False, hanger=False)
)
def test_framed_print_price(self):
self.assertEqual(598, framed_print_price(sku="GLOBAL-CFP-12x12", market=sweden))
self.assertEqual(
639,
framed_print_price(
sku="GLOBAL-CFP-12x12", market=sweden, designer=designer_moomin
),
)
self.assertEqual(
528, framed_print_price(sku="GLOBAL-CFP-12x12", market=denmark)
)
self.assertEqual(159, framed_print_price(sku="GLOBAL-CFP-28x40", market=eu))
self.assertEqual(208, framed_print_price(sku="GLOBAL-CFP-28x40", market=us))
def test_invalid_framed_print_code(self):
with self.assertRaises(ValueError) as context:
framed_print_price(sku="invalid", market=sweden)
self.assertTrue("Invalid SKU number" in str(context.exception))
def test_wallpaper_kit_price(self): def test_wallpaper_kit_price(self):
self.assertEqual(143.2, wallpaper_kit_price(market=sweden, rounded=False, inc_vat=False)) self.assertEqual(143.2, wallpaper_kit_price(market=sweden, rounded=False, inc_vat=False))
self.assertEqual(179.0, wallpaper_kit_price(market=sweden, rounded=False, inc_vat=True)) self.assertEqual(179.0, wallpaper_kit_price(market=sweden, rounded=False, inc_vat=True))
-122
View File
@@ -3,7 +3,6 @@ import flask_testing
from api import create_app, db from api import create_app, db
from api.models.product import Material, Product, Currencies from api.models.product import Material, Product, Currencies
from api.models import Inquiry, Designer, Market from api.models import Inquiry, Designer, Market
from api.lib import pwinty
class TestEndpoints(flask_testing.TestCase): class TestEndpoints(flask_testing.TestCase):
@@ -115,94 +114,6 @@ class TestEndpoints(flask_testing.TestCase):
] ]
self.assertEqual(expected, response.json["data"]) self.assertEqual(expected, response.json["data"])
def test_canvas(self):
self._add_market()
response = self.client.get("/prices/canvas?width=200&height=10&market=1")
self.assert200(response)
expected = [
{
"framed": True,
"height": 40,
"price": 1008.0,
"price_excl_vat": 806.4,
"width": 150,
},
{
"framed": False,
"height": 20,
"price": 575.47,
"price_excl_vat": 460.37600000000003,
"width": 200,
},
]
self.assertEqual(expected, response.json["data"])
def test_canvas_with_product(self):
self._add_market()
designer = self._add_designer(pricepremium_canvas=2)
product = self._add_product(designer)
response = self.client.get(
"/prices/canvas?width=200&height=10&market=1&product=1"
)
self.assert200(response)
expected = [
{
"framed": True,
"height": 40,
"price": 1028.16,
"price_excl_vat": 822.528,
"width": 150,
},
{
"framed": False,
"height": 20,
"price": 586.9794,
"price_excl_vat": 469.58352,
"width": 200,
},
]
self.assertEqual(expected, response.json["data"])
def test_diy_frame(self):
self._add_market()
response = self.client.get("/prices/diy-frame?width=200&height=50&market=1")
self.assert200(response)
product = response.json["data"][0]
self.assertEqual(150, product["width"], "it adjusts measurements")
self.assertEqual(50, product["height"])
self.assertAlmostEqual(731.25, product["price"], places=2)
def test_poster(self):
self._add_market()
response = self.client.get("/prices/poster?width=50&height=30&market=1")
self.assert200(response)
expected = [
{
"hanger": True,
"height": 30,
"price": 397.5,
"price_excl_vat": 318,
"width": 50,
},
{
"hanger": False,
"height": 30,
"price": 250.0,
"price_excl_vat": 200,
"width": 50,
},
]
self.assertEqual(expected, response.json["data"])
def test_poster_hanger(self):
self._add_market()
response = self.client.get("/prices/poster-hanger?width=50&market=1")
self.assert200(response)
product = response.json["data"][0]
self.assertEqual(210.0, product["price"])
self.assertEqual(168, product["price_excl_vat"])
self.assertEqual(50, product["width"])
def test_inquiry_wallpaper(self): def test_inquiry_wallpaper(self):
market = self._add_market() market = self._add_market()
self._add_material("standard-wallpaper", 1, 236) self._add_material("standard-wallpaper", 1, 236)
@@ -211,36 +122,3 @@ class TestEndpoints(flask_testing.TestCase):
response = self.client.get("/prices/inquiry/1?width=100&height=100") response = self.client.get("/prices/inquiry/1?width=100&height=100")
self.assert200(response) self.assert200(response)
self.assertEqual("wallpaper", response.json["group"]) self.assertEqual("wallpaper", response.json["group"])
def test_inquiry_canvas(self):
market = self._add_market()
self._add_material("standard-canvas", 2, 799.2)
self._add_inquiry(market=market, product_group="canvas")
response = self.client.get("/prices/inquiry/1?width=100&height=100")
self.assert200(response)
self.assertEqual("canvas", response.json["group"])
def test_inquiry_poster(self):
market = self._add_market()
self._add_inquiry(market=market, product_group="poster")
response = self.client.get("/prices/inquiry/1?width=100&height=100")
self.assert200(response)
self.assertEqual("poster", response.json["group"])
def test_framed_print(self):
self._add_market()
response = self.client.get("/prices/framed-print?sku=GLOBAL-CFP-12x12&market=1")
self.assert200(response)
expected = [{"price": 597.5, "price_excl_vat": 478, "sku": "GLOBAL-CFP-12x12"}]
self.assertEqual(expected, response.json["data"])
def test_framed_print_invalid_sku(self):
self._add_market()
response = self.client.get("/prices/framed-print?sku=invalid&market=1")
self.assert400(response)
self.assertEqual(
"sku contains an invalid value, must be one of: {}".format(
pwinty.SKU_CODES
),
response.json["message"],
)