Fix: Error is recipe quantity
Fix: Update did not change the recipe quantity, units, fraction, fraction_units
This commit is contained in:
parent
35413166d4
commit
30442ffecb
@ -31,8 +31,8 @@ def save(request):
|
||||
raise ValidationError('Name cannot be blank')
|
||||
|
||||
try:
|
||||
quantity = Decimal(json.get('Quantity', 0))
|
||||
if quantity < 0:
|
||||
recipe_quantity = Decimal(json.get('Quantity', 0))
|
||||
if recipe_quantity < 0:
|
||||
raise ValidationError("Quantity must be a decimal >= 0")
|
||||
except (ValueError, InvalidOperation):
|
||||
raise ValidationError("Quantity must be a decimal >= 0")
|
||||
@ -87,7 +87,7 @@ def save(request):
|
||||
product_group_id=product_group_id, ledger_id=Ledger.all_purchases(),
|
||||
price=recipe_cost, is_active=True).create()
|
||||
|
||||
recipe = Recipe(date=date, product_id=menu_item.id, quantity=quantity, sale_price=sale_price, notes='')
|
||||
recipe = Recipe(date=date, product_id=menu_item.id, quantity=recipe_quantity, sale_price=sale_price, notes='')
|
||||
recipe.product = menu_item
|
||||
DBSession.add(recipe)
|
||||
for item in recipe_items:
|
||||
@ -112,6 +112,25 @@ def update(request):
|
||||
date = datetime.datetime.strptime(json['Date'], '%d-%b-%Y')
|
||||
except (ValueError, KeyError, TypeError):
|
||||
raise ValidationError("Date is not a valid date")
|
||||
try:
|
||||
recipe.quantity = Decimal(json.get('Quantity', 0))
|
||||
if recipe.quantity < 0:
|
||||
raise ValidationError("Quantity must be a decimal >= 0")
|
||||
except (ValueError, InvalidOperation):
|
||||
raise ValidationError("Quantity must be a decimal >= 0")
|
||||
recipe.product.is_semi = json.get('IsSemi', False)
|
||||
|
||||
if recipe.product.is_semi:
|
||||
recipe.product.units = json.get('Units', '').strip()
|
||||
try:
|
||||
recipe.product.fraction = Decimal(json.get('Fraction', 0))
|
||||
if recipe.product.fraction <= 0:
|
||||
raise ValidationError("Fraction must be a decimal > 0")
|
||||
except (ValueError, InvalidOperation):
|
||||
raise ValidationError("Fraction must be a decimal > 0")
|
||||
|
||||
recipe.product.fraction_units = json.get('FractionUnits', '').strip()
|
||||
|
||||
if len(json['RecipeItems']) == 0:
|
||||
raise ValidationError("Recipe has no ingredients")
|
||||
if date == recipe.date:
|
||||
@ -240,5 +259,4 @@ def recipe_info(id):
|
||||
'FractionUnits': item.product.fraction_units, 'Fraction': item.product.fraction,
|
||||
'ProductYield': item.product.product_yield},
|
||||
'Quantity': item.quantity, 'Price': item.price})
|
||||
pass
|
||||
return info
|
||||
|
Loading…
x
Reference in New Issue
Block a user