rename material_price to m2_price
This commit is contained in:
+9
-17
@@ -5,24 +5,19 @@ from api.lib.utils import round_half_up
|
|||||||
from api.lib.limits import calculate_canvas_limits
|
from api.lib.limits import calculate_canvas_limits
|
||||||
|
|
||||||
|
|
||||||
def material_price(material, market, designer=None, reseller=None, rounded=True, inc_vat=True):
|
def m2_price(material, market, designer=None, reseller=None, rounded=True, inc_vat=True):
|
||||||
|
""" calculates price per square meter """
|
||||||
price = material.price
|
price = material.price
|
||||||
|
|
||||||
# add designer price premium
|
|
||||||
if designer:
|
if designer:
|
||||||
price *= (float(designer.pricepremium) / 100) + 1
|
price *= (float(designer.pricepremium) / 100) + 1
|
||||||
|
|
||||||
# add reseller price premium
|
|
||||||
if reseller:
|
if reseller:
|
||||||
price *= (float(reseller.pricepremium) / 100) + 1
|
price *= (float(reseller.pricepremium) / 100) + 1
|
||||||
|
|
||||||
# exchange to local currency
|
|
||||||
price *= market.exchange_rate
|
price *= market.exchange_rate
|
||||||
|
|
||||||
# multiply m2_price with market price adjustments
|
|
||||||
price *= market.price_adjustments
|
price *= market.price_adjustments
|
||||||
|
|
||||||
# add vat
|
|
||||||
if inc_vat:
|
if inc_vat:
|
||||||
price *= market.vat
|
price *= market.vat
|
||||||
|
|
||||||
@@ -33,10 +28,9 @@ def material_price(material, market, designer=None, reseller=None, rounded=True,
|
|||||||
|
|
||||||
|
|
||||||
def wallpaper_price(width, height, material, market, designer=None, reseller=None, rounded=True, inc_vat=True):
|
def wallpaper_price(width, height, material, market, designer=None, reseller=None, rounded=True, inc_vat=True):
|
||||||
m2_price = material_price(
|
price = m2_price(material, market, designer, reseller,
|
||||||
material, market, designer, reseller, rounded=rounded, inc_vat=False)
|
rounded=rounded, inc_vat=False)
|
||||||
|
|
||||||
# calculate price per square meter
|
|
||||||
sqm = (width / 100) * (height / 100)
|
sqm = (width / 100) * (height / 100)
|
||||||
|
|
||||||
if market.territory == "US":
|
if market.territory == "US":
|
||||||
@@ -46,9 +40,8 @@ def wallpaper_price(width, height, material, market, designer=None, reseller=Non
|
|||||||
|
|
||||||
sqm = max(sqm, min_sqm)
|
sqm = max(sqm, min_sqm)
|
||||||
|
|
||||||
price = sqm * m2_price
|
price *= sqm
|
||||||
|
|
||||||
# add vat
|
|
||||||
if inc_vat:
|
if inc_vat:
|
||||||
price *= market.vat
|
price *= market.vat
|
||||||
|
|
||||||
@@ -159,14 +152,13 @@ def old_canvas_diy_frame_price(width, height, market, reseller=None, rounded=Tru
|
|||||||
|
|
||||||
def old_canvas_price(width, height, material, market, framed=True, designer=None, reseller=None, inc_vat=True):
|
def old_canvas_price(width, height, material, market, framed=True, designer=None, reseller=None, inc_vat=True):
|
||||||
width, height = calculate_canvas_limits(width, height, framed)
|
width, height = calculate_canvas_limits(width, height, framed)
|
||||||
m2_price = material_price(
|
price = m2_price(material, market, designer, reseller,
|
||||||
material, market, designer, reseller, rounded=False, inc_vat=False)
|
rounded=False, inc_vat=False)
|
||||||
|
|
||||||
# calculate square meter
|
# calculate square meter
|
||||||
sqm = (width / 100) * (height / 100)
|
sqm = (width / 100) * (height / 100)
|
||||||
sqm = max(sqm, 0.2) # sqm can never go below 0.2
|
sqm = max(sqm, 0.2) # sqm can never go below 0.2
|
||||||
|
price *= sqm
|
||||||
# calculate price per square meter
|
|
||||||
price = sqm * m2_price
|
|
||||||
|
|
||||||
if framed:
|
if framed:
|
||||||
# todo: when product models are in place we should use stockproduct
|
# todo: when product models are in place we should use stockproduct
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from api.validators import validate_territory, validate_number, validate_exists
|
|||||||
from api.models.product import Material
|
from api.models.product import Material
|
||||||
from api.models.contract_customer import ContractCustomer
|
from api.models.contract_customer import ContractCustomer
|
||||||
from api.models import market as market_model
|
from api.models import market as market_model
|
||||||
from api.lib.prices import wallpaper_price, old_canvas_price, old_canvas_diy_frame_price, material_price
|
from api.lib.prices import wallpaper_price, old_canvas_price, old_canvas_diy_frame_price, m2_price
|
||||||
from api.lib.limits import calculate_canvas_limits
|
from api.lib.limits import calculate_canvas_limits
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ def wallpaper():
|
|||||||
data.append({
|
data.append({
|
||||||
'material': material.name,
|
'material': material.name,
|
||||||
'material_id': material.id,
|
'material_id': material.id,
|
||||||
'material_price': material_price(material, market, reseller=reseller, inc_vat=True),
|
'material_price': m2_price(material, market, reseller=reseller, inc_vat=True),
|
||||||
'price': wallpaper_price(width, height, material, market, reseller=reseller),
|
'price': wallpaper_price(width, height, material, market, reseller=reseller),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -43,21 +43,21 @@ standard_canvas.material_price = MaterialPrice(price=799.2)
|
|||||||
|
|
||||||
class TestPrice(unittest2.TestCase):
|
class TestPrice(unittest2.TestCase):
|
||||||
|
|
||||||
def test_material_price(self):
|
def test_m2_price(self):
|
||||||
self.assertEqual(236, material_price(
|
self.assertEqual(236, m2_price(
|
||||||
material=standard_wallpaper, market=sweden, inc_vat=False))
|
material=standard_wallpaper, market=sweden, inc_vat=False))
|
||||||
self.assertEqual(260, material_price(
|
self.assertEqual(260, m2_price(
|
||||||
material=premium_wallpaper, market=sweden, inc_vat=False))
|
material=premium_wallpaper, market=sweden, inc_vat=False))
|
||||||
self.assertEqual(295, material_price(
|
self.assertEqual(295, m2_price(
|
||||||
material=standard_wallpaper, market=sweden, inc_vat=True))
|
material=standard_wallpaper, market=sweden, inc_vat=True))
|
||||||
self.assertEqual(223, material_price(
|
self.assertEqual(223, m2_price(
|
||||||
material=standard_wallpaper, market=denmark, inc_vat=False))
|
material=standard_wallpaper, market=denmark, inc_vat=False))
|
||||||
self.assertAlmostEqual(79.92, material_price(
|
self.assertAlmostEqual(79.92, m2_price(
|
||||||
material=standard_canvas, market=russia, rounded=False, inc_vat=False), places=2)
|
material=standard_canvas, market=russia, rounded=False, inc_vat=False), places=2)
|
||||||
self.assertAlmostEqual(81.5184, material_price(
|
self.assertAlmostEqual(81.5184, m2_price(
|
||||||
material=standard_canvas, market=russia, designer=designer_moomin, rounded=False, inc_vat=False), places=4)
|
material=standard_canvas, market=russia, designer=designer_moomin, rounded=False, inc_vat=False), places=4)
|
||||||
self.assertAlmostEqual(110.88899937662403, material_price(material=standard_canvas, market=russia,
|
self.assertAlmostEqual(110.88899937662403, m2_price(material=standard_canvas, market=russia,
|
||||||
designer=designer_moomin, reseller=piterra, rounded=False, inc_vat=False), places=4)
|
designer=designer_moomin, reseller=piterra, rounded=False, inc_vat=False), places=4)
|
||||||
|
|
||||||
def test_wallpaper_price(self):
|
def test_wallpaper_price(self):
|
||||||
self.assertEqual(295, wallpaper_price(
|
self.assertEqual(295, wallpaper_price(
|
||||||
|
|||||||
Reference in New Issue
Block a user