Fix: Recipe add was not working and removed unused rate input in the recipe detail component

This commit is contained in:
2023-08-10 13:32:35 +05:30
parent 9a3bd413d6
commit e072e77663
5 changed files with 58 additions and 15 deletions

View File

@ -40,3 +40,30 @@ class Recipe:
tags: Mapped[list["Tag"]] = relationship(
"Tag", secondary=RecipeTag.__table__, order_by="Tag.name", back_populates="recipes"
)
def __init__(
self,
date_: date,
source: str,
instructions: str,
garnishing: str,
plating: str,
notes: str,
recipe_yield: Decimal,
sku_id: uuid.UUID | None = None,
sku: "StockKeepingUnit" | None = None,
id_: uuid.UUID | None = None,
):
self.date_ = date_
self.source = source
self.instructions = instructions
self.garnishing = garnishing
self.plating = plating
self.notes = notes
self.recipe_yield = recipe_yield
if sku_id is not None:
self.sku_id = sku_id
if sku is not None:
self.sku = sku
if id_ is not None:
self.id = id_

View File

@ -29,3 +29,26 @@ class RecipeItem:
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
product: Mapped["Product"] = relationship("Product")
def __init__(
self,
quantity: Decimal,
description: str = "",
recipe_id: uuid.UUID | None = None,
product_id: uuid.UUID | None = None,
recipe: "Recipe" | None = None,
product: "Product" | None = None,
id_: uuid.UUID | None = None,
):
self.quantity = quantity
self.description = description
if recipe_id is not None:
self.recipe_id = recipe_id
if product_id is not None:
self.product_id = product_id
if recipe is not None:
self.recipe = recipe
if product is not None:
self.product = product
if id_ is not None:
self.id = id_

View File

@ -58,6 +58,7 @@ def save(
instructions=data.instructions,
garnishing=data.garnishing,
plating=data.plating,
notes=data.notes,
sku=recipe_sku,
recipe_yield=round(data.recipe_yield, 2),
)
@ -71,7 +72,8 @@ def save(
r_item.recipe_id = recipe.id
db.add(r_item)
check_recursion(set([recipe_sku.product_id]), set(), recipe, db)
# TODO: Check recursion
# check_recursion(set([recipe_sku.product_id]), set(), recipe, db)
db.commit()
return recipe_info(recipe)
except SQLAlchemyError as e: