P5-3248 - Fix package price calculations

This commit is contained in:
Anders Gustafsson
2018-12-05 14:21:53 +01:00
parent 5bbc519513
commit f680f0bcc3
2 changed files with 35 additions and 18 deletions
+20 -14
View File
@@ -80,11 +80,15 @@ def canvas_cm2_price(cm2):
return cm2_price
def package_price(width, height, market):
longest_side = max(width, height)
if longest_side > 119 and market.territory in ['US', 'EU']:
return 800
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
@@ -103,7 +107,7 @@ def canvas_price(width, height, market, framed=True, designer=None, reseller=Non
price *= market.price_adjustments
# Package price should be added after market price adjustment but before other price adjustments.
price += package_price(width, height, market)
price += package_price('canvas', width, height, market)
if designer:
price *= (float(designer.pricepremium) / 100) + 1
@@ -133,11 +137,15 @@ def canvas_frame_price(width, height, market, reseller=None, rounded=True, inc_v
price = max(price, 317.44)
price *= 0.65
price *= market.price_adjustments
# Package price should be added after market price adjustment but before other price adjustments.
price += package_price('canvas', width, height, market)
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
price *= market.exchange_rate
price *= market.price_adjustments
if inc_vat:
price *= market.vat
@@ -185,12 +193,8 @@ def poster_price(width, height, market, hanger=True, designer=None, reseller=Non
price *= market.price_adjustments
# Price adjustment for high shipping costs to US and GLOBAL
if market.territory in ['US', 'EU']:
if width > 110:
price += 1100
else:
price += 400
# Package price should be added after market price adjustment but before other price adjustments.
price += package_price('poster', width, height, market)
if designer:
price *= (float(designer.pricepremium) / 100) + 1
@@ -218,7 +222,9 @@ def poster_hanger_price(width, market, reseller=None, rounded=True, inc_vat=True
price += 50 # add 50 SEK extra since they are buying only the hanger
price *= market.price_adjustments
price += package_price(width, 10, market) # we assume the poster hanger has a height of 10cm here
# Package price should be added after market price adjustment but before other price adjustments.
price += package_price('poster', width, 10, market) # we assume the poster hanger has a height of 10cm here
if reseller:
price *= (float(reseller.pricepremium) / 100) + 1
+15 -4
View File
@@ -122,8 +122,6 @@ class TestPrice(unittest2.TestCase):
self.assertEqual(299, canvas_price(width=40, height=40,
market=sweden, framed=False, inc_vat=True))
self.assertEqual(277, canvas_frame_price(
width=40, height=40, market=sweden, inc_vat=True))
self.assertEqual(731, canvas_price(width=80, height=80,
market=sweden, framed=False, inc_vat=True))
@@ -160,6 +158,14 @@ class TestPrice(unittest2.TestCase):
500, 500, market=sweden, inc_vat=False))
self.assertEqual(222, canvas_frame_price(
1, 1, market=sweden, inc_vat=False))
self.assertEqual(277, canvas_frame_price(
width=40, height=40, market=sweden, inc_vat=True))
self.assertEqual(154, canvas_frame_price(
width=40, height=120, market=us))
self.assertEqual(54, canvas_frame_price(
width=40, height=100, market=us))
self.assertEqual(578, canvas_frame_price(
width=40, height=120, market=sweden))
def test_wallpaper_custom_inquiry_price(self):
with mock.patch.object(Inquiry, 'market', nl):
@@ -245,8 +251,11 @@ class TestPrice(unittest2.TestCase):
self.assertEqual(91, inquiry_price(inquiry, framed=False))
def test_package_price(self):
self.assertEqual(800, package_price(150, 40, market=us))
self.assertEqual(0, package_price(150, 40, market=sweden))
self.assertEqual(800, package_price('canvas', 150, 40, market=us))
self.assertEqual(0, package_price('canvas', 150, 40, market=sweden))
self.assertEqual(1100, package_price('poster', 150, 40, market=us))
self.assertEqual(400, package_price('poster', 40, 40, market=us))
self.assertEqual(0, package_price('poster', 150, 40, market=sweden))
def test_poster_cm2_price(self):
self.assertEqual(0.08399104, poster_cm2_price(1))
@@ -264,3 +273,5 @@ class TestPrice(unittest2.TestCase):
def test_poster_hanger_price(self):
self.assertEqual(182, poster_hanger_price(30, market=sweden))
self.assertEqual(438, poster_hanger_price(150, market=sweden))
self.assertEqual(66, poster_hanger_price(30, market=us))
self.assertEqual(176, poster_hanger_price(150, market=us))