Fix: Recipe add was not working and removed unused rate input in the recipe detail component
This commit is contained in:
parent
9a3bd413d6
commit
e072e77663
@ -40,3 +40,30 @@ class Recipe:
|
|||||||
tags: Mapped[list["Tag"]] = relationship(
|
tags: Mapped[list["Tag"]] = relationship(
|
||||||
"Tag", secondary=RecipeTag.__table__, order_by="Tag.name", back_populates="recipes"
|
"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_
|
||||||
|
@ -29,3 +29,26 @@ class RecipeItem:
|
|||||||
|
|
||||||
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
|
recipe: Mapped["Recipe"] = relationship("Recipe", back_populates="items")
|
||||||
product: Mapped["Product"] = relationship("Product")
|
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_
|
||||||
|
@ -58,6 +58,7 @@ def save(
|
|||||||
instructions=data.instructions,
|
instructions=data.instructions,
|
||||||
garnishing=data.garnishing,
|
garnishing=data.garnishing,
|
||||||
plating=data.plating,
|
plating=data.plating,
|
||||||
|
notes=data.notes,
|
||||||
sku=recipe_sku,
|
sku=recipe_sku,
|
||||||
recipe_yield=round(data.recipe_yield, 2),
|
recipe_yield=round(data.recipe_yield, 2),
|
||||||
)
|
)
|
||||||
@ -71,7 +72,8 @@ def save(
|
|||||||
r_item.recipe_id = recipe.id
|
r_item.recipe_id = recipe.id
|
||||||
db.add(r_item)
|
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()
|
db.commit()
|
||||||
return recipe_info(recipe)
|
return recipe_info(recipe)
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row justify-around content-start items-start sm:max-lg:flex-col">
|
<div class="flex flex-row justify-around content-start items-start sm:max-lg:flex-col">
|
||||||
<mat-form-field class="flex-auto basis-3/5 mr-5">
|
<mat-form-field class="flex-auto basis-4/5 mr-5">
|
||||||
<mat-label>Product</mat-label>
|
<mat-label>Product</mat-label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@ -43,7 +43,7 @@
|
|||||||
<mat-option *ngFor="let product of products | async" [value]="product">{{ product.name }}</mat-option>
|
<mat-option *ngFor="let product of products | async" [value]="product">{{ product.name }}</mat-option>
|
||||||
</mat-autocomplete>
|
</mat-autocomplete>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="flex-auto basis-1/10 mr-5">
|
<mat-form-field class="flex-auto basis-1/5">
|
||||||
<mat-label>Yield</mat-label>
|
<mat-label>Yield</mat-label>
|
||||||
<input type="text" matInput formControlName="recipeYield" autocomplete="off" />
|
<input type="text" matInput formControlName="recipeYield" autocomplete="off" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
@ -74,17 +74,12 @@
|
|||||||
<mat-label>Quantity</mat-label>
|
<mat-label>Quantity</mat-label>
|
||||||
<input type="text" matInput formControlName="quantity" autocomplete="off" />
|
<input type="text" matInput formControlName="quantity" autocomplete="off" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="flex-auto basis-1/5 mr-5">
|
<mat-form-field class="flex-auto basis-[30%] mr-5">
|
||||||
<mat-label>Description</mat-label>
|
<mat-label>Description</mat-label>
|
||||||
<input type="text" matInput formControlName="description" autocomplete="off" />
|
<input type="text" matInput formControlName="description" autocomplete="off" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="flex-auto basis-1/10 mr-5">
|
|
||||||
<mat-label>Rate</mat-label>
|
|
||||||
<input type="text" matInput formControlName="rate" autocomplete="off" />
|
|
||||||
<span matTextPrefix>₹ </span>
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<button mat-raised-button color="primary" (click)="addRow()" class="flex-auto basis-1/10">Add</button>
|
<button mat-raised-button color="primary" (click)="addRow()" class="flex-auto basis-[10%]">Add</button>
|
||||||
</div>
|
</div>
|
||||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||||
<!-- Ingredient Column -->
|
<!-- Ingredient Column -->
|
||||||
|
@ -39,7 +39,6 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
|||||||
ingredient: FormControl<string | null>;
|
ingredient: FormControl<string | null>;
|
||||||
quantity: FormControl<string>;
|
quantity: FormControl<string>;
|
||||||
description: FormControl<string>;
|
description: FormControl<string>;
|
||||||
rate: FormControl<string>;
|
|
||||||
}>;
|
}>;
|
||||||
instructions: FormControl<string>;
|
instructions: FormControl<string>;
|
||||||
garnishing: FormControl<string>;
|
garnishing: FormControl<string>;
|
||||||
@ -75,7 +74,6 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
|||||||
ingredient: new FormControl(''),
|
ingredient: new FormControl(''),
|
||||||
quantity: new FormControl('', { nonNullable: true }),
|
quantity: new FormControl('', { nonNullable: true }),
|
||||||
description: new FormControl('', { nonNullable: true }),
|
description: new FormControl('', { nonNullable: true }),
|
||||||
rate: new FormControl('', { nonNullable: true }),
|
|
||||||
}),
|
}),
|
||||||
instructions: new FormControl('', { nonNullable: true }),
|
instructions: new FormControl('', { nonNullable: true }),
|
||||||
garnishing: new FormControl('', { nonNullable: true }),
|
garnishing: new FormControl('', { nonNullable: true }),
|
||||||
@ -118,7 +116,6 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
|||||||
ingredient: null,
|
ingredient: null,
|
||||||
quantity: '',
|
quantity: '',
|
||||||
description: '',
|
description: '',
|
||||||
rate: '',
|
|
||||||
},
|
},
|
||||||
instructions: item.instructions,
|
instructions: item.instructions,
|
||||||
garnishing: item.garnishing,
|
garnishing: item.garnishing,
|
||||||
@ -160,8 +157,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
||||||
const rate = this.math.parseAmount(formValue.rate, 2);
|
if (this.ingredient === null || quantity <= 0) {
|
||||||
if (this.ingredient === null || quantity <= 0 || rate <= 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const oldFiltered = this.item.items.filter((x) => x.product.id === (this.ingredient as ProductSku).id);
|
const oldFiltered = this.item.items.filter((x) => x.product.id === (this.ingredient as ProductSku).id);
|
||||||
|
Loading…
Reference in New Issue
Block a user