Files
api2/api/models/inquiry.py
T
2019-10-30 13:44:04 +01:00

64 lines
2.1 KiB
Python

# coding=UTF-8
from api.extensions import db
from api.models import market as market_model
from api.lib.utils import round_half_up
class Inquiry(db.Model):
__tablename__ = "inquiries"
id = db.Column("inquiryid", db.Integer, primary_key=True)
territory = db.Column(db.String(2))
product_group = db.Column(db.String(100))
price_m2 = db.Column(db.Numeric)
price_effect = db.Column(db.Numeric)
price_retouch = db.Column(db.Numeric)
width = db.Column(db.Integer)
height = db.Column(db.Integer)
framed = db.Column(db.Integer, nullable=False, default=0)
dealer_store_id = db.Column(
"dealer_store",
db.Integer,
db.ForeignKey("contract_customers.contractcustomerid"),
)
dealer_store = db.relationship("ContractCustomer", uselist=False)
hanger = db.Column(db.String)
materialid = db.Column(
db.Integer,
db.ForeignKey("product-materials.materialid"),
default=1,
nullable=False,
)
material = db.relationship("Material", uselist=False)
pricepremium = db.Column(db.Numeric, nullable=False, default=0)
productId = db.Column(db.Integer, db.ForeignKey("product-products.productid"))
product = db.relationship("Product", uselist=False)
automated = db.Column(db.Integer, nullable=False, default=0)
@property
def market(self):
market = market_model.from_territory(self.territory)
if not market:
raise ValueError("Invalid territory: {}".format(self.territory))
return market
def local_price_retouch(self, rounded=True, inc_vat=False):
""" returns the retouch price in the inquiry local currency """
if not self.price_retouch:
return 0
price = float(self.price_retouch)
price *= self.market.exchange_rate
price *= self.market.price_adjustments
if inc_vat:
price *= self.market.vat
if rounded:
price = round_half_up(price)
return price
@property
def designer(self):
if self.product and self.product.designer:
return self.product.designer
return None