refactor material prices

This commit is contained in:
Martin
2016-11-01 14:39:59 +01:00
parent bf9fc3ae5a
commit 0663bedc80
7 changed files with 79 additions and 51 deletions
+19 -8
View File
@@ -5,22 +5,33 @@ from api.lib.utils import round_half_up
from api.lib.limits import calculate_canvas_limits
def wallpaper_price(width, height, material_price, market, designer=None, reseller=None, inc_vat=True):
m2_price = material_price
def material_price(material, market, designer=None, reseller=None, inc_vat=True):
price = material.price
# add designer price premium
if designer:
m2_price *= (float(designer.pricepremium) / 100) + 1
price *= (float(designer.pricepremium) / 100) + 1
# add reseller price premium
if reseller:
m2_price *= (float(reseller.pricepremium) / 100) + 1
price *= (float(reseller.pricepremium) / 100) + 1
# exchange to local currency
m2_price *= market.exchange_rate
price *= market.exchange_rate
# multiply m2_price with market price adjustments
m2_price *= market.price_adjustments
price *= market.price_adjustments
# add vat
if inc_vat:
price *= market.vat
return round_half_up(price)
def wallpaper_price(width, height, material, market, designer=None, reseller=None, inc_vat=True):
m2_price = material_price(
material, market, designer, reseller, inc_vat=False)
# calculate price per square meter
sqm = (width / 100) * (height / 100)
@@ -140,14 +151,14 @@ def old_canvas_diy_frame_price(width, height, market, reseller=None, inc_vat=Tru
return round_half_up(price)
def old_canvas_price(width, height, material_price, 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)
# calculate square meter
sqm = (width / 100) * (height / 100)
sqm = max(sqm, 0.2) # sqm can never go below 0.2
# calculate price per square meter
price = sqm * material_price
price = sqm * material.price
if framed:
# todo: when product models are in place we should use stockproduct
+1
View File
@@ -2,3 +2,4 @@ from .designer import Designer
from .category import Category
from .contract_customer import ContractCustomer
from .inquiry import Inquiry
from .product import Material
+4 -3
View File
@@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify, abort
from api.models.product import Material
from api.models.contract_customer import ContractCustomer
from api.models import market as market_model
from api.lib.prices import wallpaper_price, old_canvas_price, old_canvas_diy_frame_price
from api.lib.prices import wallpaper_price, old_canvas_price, old_canvas_diy_frame_price, material_price
from api.lib.limits import calculate_canvas_limits
from api.validators import validate_territory, validate_number, validate_keys_exists
@@ -36,7 +36,8 @@ def wallpaper():
data.append({
'material': material.name,
'material_id': material.id,
'price': wallpaper_price(width, height, material.price, market, reseller=reseller),
'material_price': material_price(material, market, reseller=reseller, inc_vat=True),
'price': wallpaper_price(width, height, material, market, reseller=reseller),
})
return jsonify(data=data)
@@ -63,7 +64,7 @@ def canvas():
'framed': framed,
'width': width,
'height': height,
'price': old_canvas_price(width, height, material.price, market, reseller=reseller, framed=framed)
'price': old_canvas_price(width, height, material, market, reseller=reseller, framed=framed)
})
return jsonify(data=data)