# coding=UTF-8 from api.extensions import db from api.lib.utils import round_half_up class Inquiry(db.Model): __tablename__ = "inquiries" id = db.Column("inquiryid", db.Integer, primary_key=True) market_id = db.Column(db.Integer, db.ForeignKey("markets.id")) market = db.relationship("Market", backref="inquiries") 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) 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) 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 # Todo: review if the retouch price should no longer use the price_adjustments value 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