From 617c2daa06f81ff4a56c4739d9e664da897948c1 Mon Sep 17 00:00:00 2001 From: Rikard Bartholf Date: Tue, 17 Jan 2017 11:42:26 +0100 Subject: [PATCH] PW-622 Use column in materials table for getting prices Squashed commit of the following: commit 801333b25a635c5fce12d937d6808894ef2475d3 Author: Martin Date: Tue Jan 3 10:59:45 2017 +0100 PW-622 divide by float commit 9e2c696751c28c017bcb452ea4349509ca787fd9 Author: Martin Date: Mon Jan 2 13:46:57 2017 +0100 PW-622 use new material_price column --- api/lib/prices.py | 2 +- api/models/product.py | 26 ++------------------------ tests/lib/test_prices.py | 13 ++++--------- tests/resources/test_prices.py | 17 ++++++++--------- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/api/lib/prices.py b/api/lib/prices.py index d1b8518..b2a7302 100644 --- a/api/lib/prices.py +++ b/api/lib/prices.py @@ -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 diff --git a/api/models/product.py b/api/models/product.py index 7cbdb39..42f2829 100644 --- a/api/models/product.py +++ b/api/models/product.py @@ -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 { @@ -64,16 +54,4 @@ 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),) + return self.name \ No newline at end of file diff --git a/tests/lib/test_prices.py b/tests/lib/test_prices.py index 33cf563..d89009e 100644 --- a/tests/lib/test_prices.py +++ b/tests/lib/test_prices.py @@ -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): diff --git a/tests/resources/test_prices.py b/tests/resources/test_prices.py index 54deaf0..73ad5ba 100644 --- a/tests/resources/test_prices.py +++ b/tests/resources/test_prices.py @@ -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(