# coding=UTF-8 """ Price formulas """ 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 def wallpaper_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_wallpaper) / 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 inquiry_or_product_key = "product" if inquiry is None else "inquiry" price *= get_price_adjustment(market.name, material.name, inquiry_or_product_key) 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 = wallpaper_m2_price( material, market, designer, reseller, inquiry, rounded=False, inc_vat=False ) sqm = (width / 100) * (height / 100) min_sqm = 1 sqm = max(sqm, min_sqm) price *= sqm if inc_vat: price *= market.vat if rounded: price = round(price) return price 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 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) reseller = kwargs.get("reseller", inquiry.dealer_store) external_id = kwargs.get("external_id") 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, material, inquiry.market, designer=inquiry.designer, reseller=reseller, inquiry=inquiry, 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 def wallpaper_kit_price( market, reseller=None, rounded=True, inc_vat=True ): # Prices in local currency prices = { 'AT': 15.91, 'AU': 23.64, 'BE': 17.25, 'CA': 24, 'CH': 19.09, 'DE': 16.36, 'DK': 132.67, 'EE': 16.96, 'ES': 17.55, 'FI': 17.34, 'FR': 16.22, 'GB': 13.31, 'GLOBAL': 13.45, 'IE': 15.52, 'IT': 17.21, 'LU': 15.88, 'NL': 16.53, 'NO': 154.26, 'PL': 19.31, 'SE': 159.2, 'SG': 19.81, 'US': 19.81, } local_price = prices.get(market.name) if (local_price): # Note that the local wallpaper kit prices do not follow usual behaviour of multiplying by market exchange rate price = local_price else: # Default/fallback price price = prices.get('SE') price *= market.exchange_rate price *= market.price_adjustments if reseller: price *= (float(reseller.pricepremium) / 100) + 1 if inc_vat: price *= market.vat if rounded: price = round_half_up(price) return price