P5-6370 inquires should use markets instead of territores for calculating prices #36

This commit is contained in:
Martin Carlsson
2021-01-19 14:32:06 +01:00
committed by GitHub
parent 2692737100
commit dee7344ba5
6 changed files with 25 additions and 39 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ from .designer import Designer
from .category import Category
from .contract_customer import ContractCustomer
from .inquiry import Inquiry
from .product import Material, Product
from .product import Material, Product, Currencies
from .order import (
Order,
OrderField,
+3 -8
View File
@@ -9,7 +9,9 @@ class Inquiry(db.Model):
__tablename__ = "inquiries"
id = db.Column("inquiryid", db.Integer, primary_key=True)
territory = db.Column(db.String(2))
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)
@@ -36,13 +38,6 @@ class Inquiry(db.Model):
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:
+11 -7
View File
@@ -12,25 +12,29 @@ class Market(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
vat = db.Column(db.Float, nullable=False)
price_adjustment = db.Column(db.Float, nullable=False)
price_adjustments = db.Column("price_adjustment", db.Float, nullable=False)
currency = db.Column(db.String(3), db.ForeignKey("product-currencies.iso3char"))
_pc = db.relationship(Currencies, uselist=False)
exchange_rate = association_proxy("_pc", "exchange_rate", creator=lambda v: Currencies(exchange_rate=v))
@validates("name")
def validate_name(self, key, value):
raise ValueError("Name can not be modified")
exchange_rate = association_proxy("_pc", "exchange_rate")
def to_json(self):
return {
"id": self.id,
"name": self.name,
"price_adjustment": str(self.price_adjustment),
"price_adjustment": str(self.price_adjustments),
"vat": str(self.vat),
"currency": self.currency,
"exchange_rate": str(self.exchange_rate),
}
# hack: market need a territory to make it compatible with current price calculations code
# this will be removed in P5-6491
@property
def territory(self):
if self.name == 'GLOBAL':
return 'EU'
return self.name
class PriceAdjustments(db.Model):