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 """
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))
-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,
]