Add external product prices (#47)
Co-authored-by: Niklas Fondberg <niklas.fondberg@photowall.se>
This commit is contained in:
co-authored by
Niklas Fondberg
parent
f0b18c6757
commit
b1177a1e1c
+51
-1
@@ -4,6 +4,7 @@
|
||||
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
|
||||
|
||||
|
||||
def wallpaper_m2_price(
|
||||
@@ -297,6 +298,45 @@ def _price_for_poster_hanger_size(size):
|
||||
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
|
||||
if group_id == 2:
|
||||
return designer.pricepremium_canvas
|
||||
if group_id == 7:
|
||||
return designer.pricepremium_poster
|
||||
if group_id == 8:
|
||||
return designer.pricepremium_framed_print
|
||||
|
||||
raise ValueError("Unexpected group id: {}".format(group_id))
|
||||
|
||||
|
||||
def external_product_price(
|
||||
id, market, designer=None, inquiry=None, rounded=True, inc_vat=True
|
||||
):
|
||||
external_product = get_external_print_product(id)
|
||||
price = external_product["price"]
|
||||
|
||||
price *= market.price_adjustments
|
||||
|
||||
if designer:
|
||||
designer_pricepremium = _designer_pricepremium(designer, external_product["group_id"])
|
||||
price *= (float(designer_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 framed_print_price(
|
||||
sku, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True
|
||||
):
|
||||
@@ -445,8 +485,18 @@ def inquiry_price(
|
||||
hanger = kwargs.get("hanger", inquiry.hanger)
|
||||
sku = kwargs.get("sku")
|
||||
reseller = kwargs.get("reseller", inquiry.dealer_store)
|
||||
external_id = kwargs.get("external_id")
|
||||
|
||||
if inquiry.product_group == "photo-wallpaper":
|
||||
if external_id:
|
||||
price = external_product_price(
|
||||
id=external_id,
|
||||
market=inquiry.market,
|
||||
designer=inquiry.designer,
|
||||
inquiry=inquiry,
|
||||
rounded=False,
|
||||
inc_vat=False,
|
||||
)
|
||||
elif inquiry.product_group == "photo-wallpaper":
|
||||
price = wallpaper_price(
|
||||
width,
|
||||
height,
|
||||
|
||||
Reference in New Issue
Block a user