feature/pricelist #15

Merged
ferfissimo merged 11 commits from feature/pricelist into develop 2021-11-15 09:55:11 +00:00
2 changed files with 13 additions and 8 deletions
Showing only changes of commit e7b978ae3c - Show all commits

View File

@ -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):

View File

@ -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)