Add new pricing system (#65)
This commit is contained in:
@@ -3,6 +3,33 @@
|
||||
from api.lib.utils import round_half_up
|
||||
from api.models.external_print_product import get_external_print_product
|
||||
from api.models.price_adjustments import get_price_adjustment
|
||||
from api.models.prices import get_wallpaper_m2_price, get_external_product_price, get_own_image_wallpaper_m2_price, get_external_product_own_image_price
|
||||
|
||||
|
||||
def wallpaper_m2_price_new(
|
||||
product_id,
|
||||
material_id,
|
||||
market,
|
||||
inquiry=None,
|
||||
):
|
||||
own_image = inquiry is not None and inquiry.productId is None
|
||||
|
||||
if own_image:
|
||||
price_m2_incl_vat = get_own_image_wallpaper_m2_price(material_id, market.id)
|
||||
else:
|
||||
price_m2_incl_vat = get_wallpaper_m2_price(product_id, material_id, market.id)
|
||||
|
||||
price_m2_excl_vat = price_m2_incl_vat / market.vat
|
||||
|
||||
if inquiry:
|
||||
inquiry_premium = (float(inquiry.pricepremium) / 100) + 1
|
||||
price_m2_excl_vat = price_m2_excl_vat * inquiry_premium
|
||||
price_m2_incl_vat = price_m2_excl_vat * market.vat
|
||||
|
||||
return {
|
||||
"incl_vat": price_m2_incl_vat,
|
||||
"excl_vat": price_m2_excl_vat,
|
||||
}
|
||||
|
||||
|
||||
def wallpaper_m2_price(
|
||||
@@ -41,6 +68,34 @@ def wallpaper_m2_price(
|
||||
return price
|
||||
|
||||
|
||||
def wallpaper_price_new(
|
||||
product_id,
|
||||
width,
|
||||
height,
|
||||
material,
|
||||
market,
|
||||
inquiry=None,
|
||||
):
|
||||
m2_prices = wallpaper_m2_price_new(product_id, material.id, market, inquiry)
|
||||
|
||||
sqm = (width / 100) * (height / 100)
|
||||
|
||||
min_sqm = 1
|
||||
|
||||
sqm = max(sqm, min_sqm)
|
||||
|
||||
price_excl_vat = m2_prices["excl_vat"] * sqm
|
||||
|
||||
price_incl_vat = price_excl_vat * market.vat
|
||||
|
||||
return {
|
||||
"incl_vat": price_incl_vat,
|
||||
"excl_vat": price_excl_vat,
|
||||
"m2_price_incl_vat": m2_prices["incl_vat"],
|
||||
"m2_price_excl_vat": m2_prices["excl_vat"],
|
||||
}
|
||||
|
||||
|
||||
def wallpaper_price(
|
||||
width,
|
||||
height,
|
||||
@@ -86,6 +141,28 @@ def _designer_pricepremium(designer, group_id):
|
||||
raise ValueError("Unexpected group id: {}".format(group_id))
|
||||
|
||||
|
||||
def external_product_own_image_price(external_product_id, market):
|
||||
price_incl_vat = get_external_product_own_image_price(external_product_id, market.id)
|
||||
|
||||
price_excl_vat = price_incl_vat / market.vat
|
||||
|
||||
return {
|
||||
'incl_vat': price_incl_vat,
|
||||
'excl_vat': price_excl_vat,
|
||||
}
|
||||
|
||||
|
||||
def external_product_price_new(product_id, external_product_id, market):
|
||||
price_incl_vat = get_external_product_price(product_id, external_product_id, market.id)
|
||||
|
||||
price_excl_vat = price_incl_vat / market.vat
|
||||
|
||||
return {
|
||||
'incl_vat': price_incl_vat,
|
||||
'excl_vat': price_excl_vat,
|
||||
}
|
||||
|
||||
|
||||
def external_product_price(
|
||||
id, market, designer=None, inquiry=None, rounded=True, inc_vat=True
|
||||
):
|
||||
@@ -112,6 +189,54 @@ def external_product_price(
|
||||
return price
|
||||
|
||||
|
||||
def inquiry_price_new(
|
||||
inquiry, **kwargs
|
||||
):
|
||||
width = kwargs.get("width", inquiry.width)
|
||||
height = kwargs.get("height", inquiry.height)
|
||||
material = kwargs.get("material", inquiry.material)
|
||||
external_id = kwargs.get("external_id")
|
||||
|
||||
product_id = inquiry.productId
|
||||
is_own_image = product_id is None
|
||||
|
||||
if external_id:
|
||||
if not is_own_image:
|
||||
raise ValueError("Manual inquiries only available for wallpapers")
|
||||
prices = external_product_own_image_price(external_id, inquiry.market)
|
||||
return prices
|
||||
elif inquiry.product_group == "photo-wallpaper":
|
||||
if is_own_image:
|
||||
prices = wallpaper_price_new(None, width, height, material, inquiry.market, inquiry)
|
||||
else:
|
||||
prices = wallpaper_price_new(product_id, width, height, material, inquiry.market, inquiry)
|
||||
else:
|
||||
raise ValueError("Invalid product group: {}".format(inquiry.product_group))
|
||||
|
||||
price_excl_vat = prices["excl_vat"]
|
||||
effect_price = inquiry.price_effect
|
||||
if effect_price:
|
||||
price_excl_vat += float(effect_price)
|
||||
|
||||
price_excl_retouch_excl_vat = price_excl_vat
|
||||
price_excl_retouch_incl_vat = price_excl_retouch_excl_vat * inquiry.market.vat
|
||||
|
||||
retouch_price = inquiry.local_price_retouch(rounded=False, inc_vat=False)
|
||||
if retouch_price:
|
||||
price_excl_vat += retouch_price
|
||||
|
||||
price_incl_vat = price_excl_vat * inquiry.market.vat
|
||||
|
||||
return {
|
||||
"incl_vat": price_incl_vat,
|
||||
"excl_vat": price_excl_vat,
|
||||
"excl_retouch_incl_vat": price_excl_retouch_incl_vat,
|
||||
"excl_retouch_excl_vat": price_excl_retouch_excl_vat,
|
||||
"m2_price_incl_vat": prices["m2_price_incl_vat"],
|
||||
"m2_price_excl_vat": prices["m2_price_excl_vat"],
|
||||
}
|
||||
|
||||
|
||||
def inquiry_price(
|
||||
inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user