Remove old routes and code (#52)
This commit is contained in:
@@ -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
|
||||
@@ -2,8 +2,6 @@
|
||||
""" Price formulas """
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -75,229 +73,6 @@ def wallpaper_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):
|
||||
if group_id in [1,3,6]:
|
||||
return designer.pricepremium_wallpaper
|
||||
@@ -337,153 +112,12 @@ def external_product_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(
|
||||
inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs
|
||||
):
|
||||
width = kwargs.get("width", inquiry.width)
|
||||
height = kwargs.get("height", inquiry.height)
|
||||
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)
|
||||
external_id = kwargs.get("external_id")
|
||||
|
||||
@@ -508,41 +142,6 @@ def inquiry_price(
|
||||
rounded=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:
|
||||
raise ValueError("Invalid product group: {}".format(inquiry.product_group))
|
||||
|
||||
|
||||
@@ -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,
|
||||
]
|
||||
@@ -10,20 +10,13 @@ from api.models import (
|
||||
PrintProduct,
|
||||
ContractCustomer,
|
||||
)
|
||||
from api.lib import pwinty
|
||||
from api.lib.prices import (
|
||||
wallpaper_price,
|
||||
canvas_price,
|
||||
canvas_frame_price,
|
||||
poster_price,
|
||||
poster_hanger_price,
|
||||
framed_print_price,
|
||||
wallpaper_m2_price,
|
||||
inquiry_price,
|
||||
wallpaper_kit_price,
|
||||
external_product_price,
|
||||
)
|
||||
from api.lib.limits import calculate_canvas_limits
|
||||
|
||||
mod = Blueprint("prices", __name__, url_prefix="/prices")
|
||||
mod.before_request(check_api_key)
|
||||
@@ -106,129 +99,6 @@ def wallpaper():
|
||||
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"])
|
||||
@validate_exists("market")
|
||||
def wallpaper_kit():
|
||||
@@ -248,65 +118,6 @@ def wallpaper_kit():
|
||||
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):
|
||||
""" this function returns width and height to be used in the price calculations """
|
||||
|
||||
@@ -402,130 +213,6 @@ def inquiry_wallpaper(inquiry):
|
||||
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):
|
||||
data = {
|
||||
"id": inquiry.id,
|
||||
@@ -551,47 +238,10 @@ def inquiry_external_product(inquiry, external_id):
|
||||
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"])
|
||||
def inquiry(inquiry_id):
|
||||
inquiry = Inquiry.query.get_or_404(inquiry_id)
|
||||
external_product_id = request.args.get("external_product_id")
|
||||
sku = request.args.get("sku", type=str)
|
||||
listprice = request.args.get("listprice")
|
||||
|
||||
if (listprice):
|
||||
@@ -606,12 +256,6 @@ def inquiry(inquiry_id):
|
||||
data = inquiry_external_product(inquiry, external_product_id)
|
||||
elif inquiry.product_group == "photo-wallpaper":
|
||||
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:
|
||||
raise ValueError("Invalid group {}".format(inquiry.product_group))
|
||||
|
||||
@@ -666,77 +310,6 @@ def list_prices_poster_external(market_id):
|
||||
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"])
|
||||
@validate_exists("market")
|
||||
@validate_exists("id")
|
||||
|
||||
Reference in New Issue
Block a user