feature/pricelist #15
|
@ -76,16 +76,17 @@ class DrinkIngredient(db.Model, ModelSerializeMixin):
|
|||
id: int = db.Column("id", db.Integer, primary_key=True)
|
||||
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"))
|
||||
# drink_ingredient: Drink = db.relationship("Drink")
|
||||
# price: float = 0
|
||||
cost_per_volume: float
|
||||
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
|
||||
# def price(self):
|
||||
# try:
|
||||
# return self.drink_ingredient.cost_price_pro_volume * self.volume
|
||||
# except AttributeError:
|
||||
# pass
|
||||
@property
|
||||
def name(self):
|
||||
return self._drink_ingredient.name if self._drink_ingredient else None
|
||||
|
||||
|
||||
class Ingredient(db.Model, ModelSerializeMixin):
|
||||
|
|
|
@ -315,6 +315,10 @@ def delete_price(identifier):
|
|||
def set_drink_ingredient(data):
|
||||
allowed_keys = DrinkIngredient().serialize().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)
|
||||
if ingredient_id < 0:
|
||||
drink_ingredient = DrinkIngredient(**values)
|
||||
|
|
Loading…
Reference in New Issue