PW-567 add the old canvas formula
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# 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
|
||||
+81
-1
@@ -1,7 +1,9 @@
|
||||
# coding=UTF-8
|
||||
|
||||
""" Price formulas """
|
||||
|
||||
from api.lib.utils import round_half_up
|
||||
from api.lib.limits import calculate_canvas_limits
|
||||
|
||||
|
||||
def wallpaper_price(width, height, material_price, market, designer=None, reseller=None, inc_vat=True):
|
||||
m2_price = material_price
|
||||
@@ -96,3 +98,81 @@ def canvas_price(width, height, market, framed=True, designer=None, reseller=Non
|
||||
price *= market.vat
|
||||
|
||||
return round(price)
|
||||
|
||||
|
||||
def canvas_frame_price(width, height, stock_price, additional_price=None):
|
||||
width, height = calculate_canvas_limits(width, height, framed=True)
|
||||
circumference = (2 * width) + (2 * height)
|
||||
circumference = max(circumference, 170)
|
||||
|
||||
price = stock_price * circumference
|
||||
|
||||
# if width or height goes above this limit additional costs are added
|
||||
if additional_price:
|
||||
additional_price_limit = 120
|
||||
if width > additional_price_limit or height > additional_price_limit:
|
||||
price += additional_price
|
||||
|
||||
return price
|
||||
|
||||
|
||||
def old_canvas_diy_frame_price(width, height, market, reseller=None, inc_vat=True):
|
||||
# todo: when product models are in place we should use stockproduct ""Do it yourself frame""
|
||||
# instead of hardcoded values
|
||||
stock_price = 1.61084
|
||||
additional_price = 94.750000
|
||||
price = canvas_frame_price(width, height, stock_price, additional_price)
|
||||
|
||||
# exchange to local currency
|
||||
price *= market.exchange_rate
|
||||
|
||||
# multiply price with market price adjustments
|
||||
price *= market.price_adjustments
|
||||
|
||||
# add reseller price premium
|
||||
if reseller:
|
||||
price *= (float(reseller.pricepremium) / 100) + 1
|
||||
|
||||
# add vat
|
||||
if inc_vat:
|
||||
price *= market.vat
|
||||
|
||||
return round_half_up(price)
|
||||
|
||||
|
||||
def old_canvas_price(width, height, material_price, market, framed=True, designer=None, reseller=None, inc_vat=True):
|
||||
width, height = calculate_canvas_limits(width, height, framed)
|
||||
# calculate square meter
|
||||
sqm = (width / 100) * (height / 100)
|
||||
sqm = max(sqm, 0.2) # sqm can never go below 0.2
|
||||
|
||||
# calculate price per square meter
|
||||
price = sqm * material_price
|
||||
|
||||
if framed:
|
||||
# todo: when product models are in place we should use stockproduct
|
||||
# "Canvasframe" instead of hardcoded values
|
||||
stock_price = 1.04230824
|
||||
additional_price = 94.750000
|
||||
price += canvas_frame_price(width, height,
|
||||
stock_price, additional_price)
|
||||
|
||||
# add designer price premium
|
||||
if designer:
|
||||
price *= (float(designer.pricepremium) / 100) + 1
|
||||
|
||||
# add reseller price premium
|
||||
if reseller:
|
||||
price *= (float(reseller.pricepremium) / 100) + 1
|
||||
|
||||
# exchange to local currency
|
||||
price *= market.exchange_rate
|
||||
|
||||
# multiply price with market price adjustments
|
||||
price *= market.price_adjustments
|
||||
|
||||
# add vat
|
||||
if inc_vat:
|
||||
price *= market.vat
|
||||
|
||||
return round_half_up(price)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
|
||||
def round_half_up(val):
|
||||
return int(Decimal(val).quantize(0, ROUND_HALF_UP))
|
||||
Reference in New Issue
Block a user