PW-622 Use column in materials table for getting prices
Squashed commit of the following: commit 801333b25a635c5fce12d937d6808894ef2475d3 Author: Martin <me.carlsson@gmail.com> Date: Tue Jan 3 10:59:45 2017 +0100 PW-622 divide by float commit 9e2c696751c28c017bcb452ea4349509ca787fd9 Author: Martin <me.carlsson@gmail.com> Date: Mon Jan 2 13:46:57 2017 +0100 PW-622 use new material_price column
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ from api.lib.limits import calculate_canvas_limits
|
||||
|
||||
def m2_price(material, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
||||
""" calculates price per square meter """
|
||||
price = material.price
|
||||
price = material.price / 100.0
|
||||
|
||||
if designer:
|
||||
price *= (float(designer.pricepremium) / 100) + 1
|
||||
|
||||
+1
-23
@@ -43,18 +43,8 @@ class Material(db.Model):
|
||||
|
||||
id = db.Column('materialid', db.Integer, primary_key=True)
|
||||
name = db.Column('material', db.String(255), nullable=False)
|
||||
material_price = db.relationship('MaterialPrice', uselist=False)
|
||||
price = db.Column('price', db.Integer)
|
||||
|
||||
@property
|
||||
def price(self):
|
||||
if self.material_price is not None:
|
||||
return float(self.material_price.price)
|
||||
return None
|
||||
|
||||
@price.setter
|
||||
def price(self, value):
|
||||
if self.material_price:
|
||||
self.material_price.price = value
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
@@ -65,15 +55,3 @@ class Material(db.Model):
|
||||
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class MaterialPrice(db.Model):
|
||||
|
||||
__tablename__ = 'v_materialprice'
|
||||
|
||||
groupid = db.Column(db.Integer)
|
||||
materialid = db.Column(db.Integer, db.ForeignKey(
|
||||
'product-materials.materialid'))
|
||||
price = db.Column(db.Numeric)
|
||||
|
||||
__table_args__ = (db.PrimaryKeyConstraint(groupid, materialid),)
|
||||
|
||||
@@ -6,7 +6,7 @@ from tests.factories import DesignerFactory, ContractCustomerFactory, InquiryFac
|
||||
from api.models import market
|
||||
from api.models import Inquiry
|
||||
from api.models import Product
|
||||
from api.models.product import Material, MaterialPrice
|
||||
from api.models.product import Material
|
||||
|
||||
|
||||
sweden = market.from_territory('SE')
|
||||
@@ -37,14 +37,9 @@ piterra = ContractCustomerFactory(pricepremium=36.029411)
|
||||
designer_moomin = DesignerFactory()
|
||||
designer_moomin.pricepremium = 2
|
||||
|
||||
standard_wallpaper = Material(name='standard-wallpaper')
|
||||
standard_wallpaper.material_price = MaterialPrice(price=236)
|
||||
|
||||
premium_wallpaper = Material(name='premium-wallpaper')
|
||||
premium_wallpaper.material_price = MaterialPrice(price=260)
|
||||
|
||||
standard_canvas = Material(name='standard-canvas')
|
||||
standard_canvas.material_price = MaterialPrice(price=799.2)
|
||||
standard_wallpaper = Material(name='standard-wallpaper', price=23600)
|
||||
premium_wallpaper = Material(name='premium-wallpaper', price=26000)
|
||||
standard_canvas = Material(name='standard-canvas', price=79920)
|
||||
|
||||
|
||||
class TestPrice(unittest2.TestCase):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import flask_testing
|
||||
from api import create_app, db
|
||||
from api.models.product import Material, MaterialPrice, Product
|
||||
from api.models.product import Material, Product
|
||||
from api.models.inquiry import Inquiry
|
||||
from api.models.designer import Designer
|
||||
|
||||
@@ -19,8 +19,7 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
db.drop_all()
|
||||
|
||||
def _add_material(self, name, groupid, price):
|
||||
material = Material(name=name)
|
||||
material.material_price = MaterialPrice(price=price, groupid=groupid)
|
||||
material = Material(name=name, price=price)
|
||||
db.session.add(material)
|
||||
db.session.commit()
|
||||
return material
|
||||
@@ -46,8 +45,8 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
return product
|
||||
|
||||
def test_wallpaper(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
self._add_material('standard-wallpaper', 1, 23600)
|
||||
self._add_material('premium-wallpaper', 1, 26000)
|
||||
response = self.client.get(
|
||||
'/prices/wallpaper?width=200&height=10&territory=SE')
|
||||
self.assert200(response)
|
||||
@@ -72,8 +71,8 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_wallpaper_with_product(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
self._add_material('standard-wallpaper', 1, 23600)
|
||||
self._add_material('premium-wallpaper', 1, 26000)
|
||||
designer = self._add_designer(4)
|
||||
product = self._add_product(designer)
|
||||
response = self.client.get(
|
||||
@@ -99,7 +98,7 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_canvas(self):
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
self._add_material('standard-canvas', 2, 79920)
|
||||
response = self.client.get(
|
||||
'/prices/canvas?width=200&height=10&territory=SE')
|
||||
self.assert200(response)
|
||||
@@ -126,7 +125,7 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_canvas_with_product(self):
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
self._add_material('standard-canvas', 2, 79920)
|
||||
designer = self._add_designer(4)
|
||||
product = self._add_product(designer)
|
||||
response = self.client.get(
|
||||
|
||||
Reference in New Issue
Block a user