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:
Rikard Bartholf
2017-01-17 11:42:26 +01:00
parent 5ad053a09b
commit 617c2daa06
4 changed files with 15 additions and 43 deletions
+1 -1
View File
@@ -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
+2 -24
View File
@@ -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