Skip to content

Commit

Permalink
feat: GET/raw_ materials now provide related recipes, supply cost cal…
Browse files Browse the repository at this point in the history
…culation
  • Loading branch information
lucasbpro committed Jun 22, 2021
1 parent a6740ae commit a11a0d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
inserts/
venv/
data.db
data.db
app.py
3 changes: 2 additions & 1 deletion models/raw_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def json(self):
'package_amt' : self.package_amt,
'unit_material': self.unit_material,
'stock_amt' : self.stock_amt,
'sell_by' : self.sell_by_date
'sell_by' : self.sell_by_date,
'recipes' : [recipe.json()["id"] for recipe in self.recipes]
}

def save_to_db(self):
Expand Down
6 changes: 6 additions & 0 deletions resources/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def post(self):
if material:
recipe.materials.append(material)
materialRecipeItem = RecipeMaterialAmountModel.find_by_map(recipe.id, materialId)

# in case recipe-material map already exists, then just updates it
if materialRecipeItem:
materialRecipeItem.amount = materialAmount
Expand All @@ -159,6 +160,11 @@ def post(self):
else:
materialRecipeItem = RecipeMaterialAmountModel(recipe.id, materialId, materialAmount)
materialRecipeItem.save_to_db()

material_unit_price = material.package_price/material.package_amt
recipe.supply_cost += material_unit_price*materialAmount


# in case any materialId provided does not exist
else:
return {"message": constants['MATERIAL_NOT_EXIST'].format(materialId)}, 200
Expand Down

0 comments on commit a11a0d3

Please sign in to comment.