From 35413166d45f5e8978c30b3b2f45b803a4bf63c2 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Tue, 29 Apr 2014 16:38:31 +0530 Subject: [PATCH] Fix: Units not showing in recipe list Fix: Recipe update gave error --- brewman/views/recipe.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/brewman/views/recipe.py b/brewman/views/recipe.py index 15153d04..f517ebe8 100644 --- a/brewman/views/recipe.py +++ b/brewman/views/recipe.py @@ -132,6 +132,9 @@ def update(request): recipe_cost += rate * quantity recipe_items.append(RecipeItem(None, product.id, quantity, ingredient_price)) recipe.product.price = recipe_cost + for i in range(len(recipe.recipe_items), 0, -1): + recipe_item = recipe.recipe_items.pop() + DBSession.delete(recipe_item) recipe.recipe_items = [] for recipe_item in recipe_items: recipe_item.recipe_id = recipe.id @@ -209,10 +212,11 @@ def show_list(request): 'Price': cost_rate, 'Quantity': recipe_item.quantity}) costing = 0 if item.sale_price == 0 else cost_price / item.sale_price current_costing = 0 if item.sale_price == 0 else current_cost_price / item.sale_price - recipe = {'Name': item.product.name, 'Date': item.date.strftime('%d-%b-%Y'), 'SalePrice': item.sale_price, - 'CostPrice': cost_price, 'CurrentCostPrice': current_cost_price, 'Costing': costing, - 'CurrentCosting': current_costing, 'IsSemi': item.product.is_semi, 'RecipeItems': recipe_items, - 'IsLatest': previous_product_id != item.product.id, 'Url': request.route_url('recipe_id', id=item.id)} + recipe = {'Name': item.product.name, 'Units': item.product.units, 'Date': item.date.strftime('%d-%b-%Y'), + 'SalePrice': item.sale_price, 'CostPrice': cost_price, 'CurrentCostPrice': current_cost_price, + 'Costing': costing, 'CurrentCosting': current_costing, 'IsSemi': item.product.is_semi, + 'RecipeItems': recipe_items, 'IsLatest': previous_product_id != item.product.id, + 'Url': request.route_url('recipe_id', id=item.id)} recipes.append(recipe) previous_product_id = item.product.id return recipes