improve canvas-frame price calculations

This commit is contained in:
Martin
2016-11-08 13:24:08 +01:00
parent cf5fe9fc69
commit 1d6e2cc354
2 changed files with 25 additions and 18 deletions
+15 -14
View File
@@ -114,7 +114,7 @@ def canvas_price(width, height, market, framed=True, designer=None, reseller=Non
return round(price)
def canvas_frame_price(width, height, stock_price, additional_price=None):
def canvas_frame_price(width, height, stock_price, market, additional_price=None, reseller=None, rounded=True, inc_vat=True):
width, height = calculate_canvas_limits(width, height, framed=True)
circumference = (2 * width) + (2 * height)
circumference = max(circumference, 170)
@@ -127,16 +127,6 @@ def canvas_frame_price(width, height, stock_price, additional_price=None):
if width > additional_price_limit or height > additional_price_limit:
price += additional_price
return price
def old_canvas_diy_frame_price(width, height, market, reseller=None, inc_vat=True):
# todo: when product models are in place we should use stockproduct ""Do it yourself frame""
# instead of hardcoded values
stock_price = 1.61084
additional_price = 94.750000
price = canvas_frame_price(width, height, stock_price, additional_price)
# exchange to local currency
price *= market.exchange_rate
@@ -151,7 +141,18 @@ def old_canvas_diy_frame_price(width, height, market, reseller=None, inc_vat=Tru
if inc_vat:
price *= market.vat
return round_half_up(price)
if rounded:
price = round_half_up(price)
return price
def old_canvas_diy_frame_price(width, height, market, reseller=None, inc_vat=True):
# todo: when product models are in place we should use stockproduct ""Do it yourself frame""
# instead of hardcoded values
stock_price = 1.61084
additional_price = 94.750000
return canvas_frame_price(width, height, stock_price, market, additional_price, reseller=reseller, rounded=True, inc_vat=True)
def old_canvas_price(width, height, material, market, framed=True, designer=None, reseller=None, inc_vat=True):
@@ -170,8 +171,8 @@ def old_canvas_price(width, height, material, market, framed=True, designer=None
# "Canvasframe" instead of hardcoded values
stock_price = 1.04230824
additional_price = 94.750000
price += canvas_frame_price(width, height,
stock_price, additional_price)
price += canvas_frame_price(width, height, stock_price, market,
additional_price=additional_price, reseller=reseller, rounded=False, inc_vat=False)
# add vat
if inc_vat:
+10 -4
View File
@@ -116,12 +116,14 @@ class TestPrice(unittest2.TestCase):
market=denmark, framed=True, inc_vat=False))
def test_canvas_frame_price(self):
self.assertAlmostEqual(208.46, canvas_frame_price(
50, 50, stock_price=1.04230824, additional_price=94.750000), places=2)
self.assertAlmostEqual(416.923, canvas_frame_price(width=100, height=100, stock_price=1.04230824,
additional_price=94.75, market=sweden, rounded=False, inc_vat=False), places=2)
self.assertAlmostEqual(177.19, canvas_frame_price(
1, 1, stock_price=1.04230824, additional_price=94.750000), places=2)
1, 1, stock_price=1.04230824, additional_price=94.750000, market=sweden, rounded=False, inc_vat=False), places=2)
self.assertAlmostEqual(625.38, canvas_frame_price(
500, 500, stock_price=1.04230824, additional_price=None), places=2)
500, 500, stock_price=1.04230824, additional_price=None, market=sweden, rounded=False, inc_vat=False), places=2)
self.assertAlmostEqual(41.692, canvas_frame_price(
width=100, height=100, stock_price=1.04230824, additional_price=94.75, rounded=False, market=russia), places=2)
def test_old_canvas_diy_frame_price(self):
self.assertEqual(
@@ -132,6 +134,8 @@ class TestPrice(unittest2.TestCase):
50, 50, market=sweden, reseller=reseller))
self.assertEqual(1327, old_canvas_diy_frame_price(
500, 500, market=sweden))
self.assertEqual(88, old_canvas_diy_frame_price(
100, 100, market=russia, reseller=piterra))
def test_old_canvas_price(self):
self.assertEqual(250, old_canvas_price(
@@ -154,3 +158,5 @@ class TestPrice(unittest2.TestCase):
width=150, height=140, material=standard_canvas, market=sweden, framed=True))
self.assertEqual(287, old_canvas_price(
width=50, height=50, material=standard_canvas, market=sweden, framed=False, reseller=reseller))
self.assertEqual(111, old_canvas_price(width=100, height=100, material=standard_canvas, market=russia, framed=False,
designer=designer_moomin, reseller=piterra))