296 lines
8.1 KiB
Python
296 lines
8.1 KiB
Python
# coding=UTF-8
|
|
""" Price formulas """
|
|
|
|
from api.lib.utils import round_half_up
|
|
from api.lib.limits import calculate_canvas_limits
|
|
|
|
|
|
def m2_price(material, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
|
""" calculates price per square meter """
|
|
price = material.price / 100.0
|
|
|
|
if designer:
|
|
price *= (float(designer.pricepremium) / 100) + 1
|
|
|
|
if reseller:
|
|
price *= (float(reseller.pricepremium) / 100) + 1
|
|
|
|
if inquiry:
|
|
price *= (float(inquiry.pricepremium) / 100) + 1
|
|
|
|
price *= market.exchange_rate
|
|
price *= market.price_adjustments
|
|
|
|
if inc_vat:
|
|
price *= market.vat
|
|
|
|
if rounded:
|
|
price = round_half_up(price)
|
|
|
|
return price
|
|
|
|
|
|
def wallpaper_price(width, height, material, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
|
price = m2_price(material, market, designer, reseller,
|
|
inquiry, rounded=rounded, inc_vat=False)
|
|
|
|
sqm = (width / 100) * (height / 100)
|
|
|
|
if market.territory == "US":
|
|
min_sqm = 2
|
|
else:
|
|
min_sqm = 1
|
|
|
|
sqm = max(sqm, min_sqm)
|
|
|
|
price *= sqm
|
|
|
|
if inc_vat:
|
|
price *= market.vat
|
|
|
|
if rounded:
|
|
price = round(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.territory in ['US', 'EU']:
|
|
if product_group == 'canvas' and max(width, height) > 119:
|
|
return 800
|
|
elif product_group == 'poster':
|
|
if width > 110:
|
|
return 1100
|
|
else:
|
|
return 400
|
|
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) / 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.084
|
|
price_cm2_at_5000cm2 = 0.0392
|
|
price_cm2_at_10000cm2 = 0.0336
|
|
price_cm2_at_22500cm2 = 0.028
|
|
|
|
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, 134.4) # the price can never go below 134.4 SEK
|
|
|
|
if(hanger):
|
|
price += _price_for_poster_hanger_size(width)
|
|
|
|
price *= market.price_adjustments
|
|
|
|
if designer:
|
|
price *= (float(designer.pricepremium) / 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 95.2
|
|
if size > 30 and size <= 50:
|
|
return 135.2
|
|
if size > 50 and size <= 60:
|
|
return 143.2
|
|
if size > 60 and size <= 70:
|
|
return 151.2
|
|
if size > 70 and size <= 100:
|
|
return 220
|
|
if size > 100 and size <= 125:
|
|
return 250
|
|
if size > 125 and size <= 150:
|
|
return 300
|
|
|
|
raise ValueError('Invalid poster hanger size: {}'.format(size))
|
|
|
|
|
|
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)
|
|
reseller = kwargs.get('reseller', inquiry.dealer_store)
|
|
|
|
if inquiry.product_group == 'photo-wallpaper':
|
|
price = wallpaper_price(width, height, material, inquiry.market,
|
|
designer=inquiry.designer, reseller=reseller, inquiry=inquiry, 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':
|
|
price = poster_price(width, height, inquiry.market,
|
|
designer=inquiry.designer, reseller=reseller, inquiry=inquiry, hanger=hanger, rounded=False, inc_vat=False)
|
|
else:
|
|
raise ValueError(
|
|
'Invalid product group: {}'.format(inquiry.product_group))
|
|
|
|
effect_price = inquiry.price_effect
|
|
if effect_price:
|
|
price += float(effect_price)
|
|
|
|
if inc_price_retouch:
|
|
retouch_price = inquiry.local_price_retouch(
|
|
rounded=False, inc_vat=False)
|
|
if retouch_price:
|
|
price += retouch_price
|
|
|
|
if inc_vat:
|
|
price *= inquiry.market.vat
|
|
|
|
if rounded:
|
|
price = round_half_up(price)
|
|
|
|
return price
|