better drink dependency
drink_ingredient has name and cost_per_volume Flaschengeist/flaschengeist-pricelist#2
This commit is contained in:
parent
ff1a0544f8
commit
e7b978ae3c
|
@ -76,16 +76,17 @@ class DrinkIngredient(db.Model, ModelSerializeMixin):
|
||||||
id: int = db.Column("id", db.Integer, primary_key=True)
|
id: int = db.Column("id", db.Integer, primary_key=True)
|
||||||
volume: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False)
|
volume: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False)
|
||||||
ingredient_id: int = db.Column(db.Integer, db.ForeignKey("drink.id"))
|
ingredient_id: int = db.Column(db.Integer, db.ForeignKey("drink.id"))
|
||||||
# drink_ingredient: Drink = db.relationship("Drink")
|
cost_per_volume: float
|
||||||
# price: float = 0
|
name: str
|
||||||
|
_drink_ingredient: Drink = db.relationship("Drink")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cost_per_volume(self):
|
||||||
|
return self._drink_ingredient.cost_per_volume if self._drink_ingredient else None
|
||||||
|
|
||||||
# @property
|
@property
|
||||||
# def price(self):
|
def name(self):
|
||||||
# try:
|
return self._drink_ingredient.name if self._drink_ingredient else None
|
||||||
# return self.drink_ingredient.cost_price_pro_volume * self.volume
|
|
||||||
# except AttributeError:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
class Ingredient(db.Model, ModelSerializeMixin):
|
class Ingredient(db.Model, ModelSerializeMixin):
|
||||||
|
|
|
@ -315,6 +315,10 @@ def delete_price(identifier):
|
||||||
def set_drink_ingredient(data):
|
def set_drink_ingredient(data):
|
||||||
allowed_keys = DrinkIngredient().serialize().keys()
|
allowed_keys = DrinkIngredient().serialize().keys()
|
||||||
values = {key: value for key, value in data.items() if key in allowed_keys}
|
values = {key: value for key, value in data.items() if key in allowed_keys}
|
||||||
|
if "cost_per_volume" in values:
|
||||||
|
values.pop("cost_per_volume")
|
||||||
|
if "name" in values:
|
||||||
|
values.pop("name")
|
||||||
ingredient_id = values.pop("id", -1)
|
ingredient_id = values.pop("id", -1)
|
||||||
if ingredient_id < 0:
|
if ingredient_id < 0:
|
||||||
drink_ingredient = DrinkIngredient(**values)
|
drink_ingredient = DrinkIngredient(**values)
|
||||||
|
|
Loading…
Reference in New Issue