Эх сурвалжийг харах

Properly store the base unit multiplier for ingredients.

Lee Morgan 5 жил өмнө
parent
commit
cfa7ccd19a

+ 1 - 1
views/dashboardPage/js/classes/Ingredient.js

@@ -155,7 +155,7 @@ class Ingredient{
     calculateRecipeMultiplier(recipeQuantity, ingredientQuantity){
         let unitToBase = controller.baseUnit(ingredientQuantity, this._unit);
 
-        return unitToBase / recipeQuantity;
+        return  recipeQuantity / unitToBase;
     }
 }
 

+ 0 - 2
views/dashboardPage/js/classes/Transaction.js

@@ -55,9 +55,7 @@ class Transaction{
     getIngredientQuantityBase(ingredient){
         let total = 0;
         for(let i = 0; i < this._recipes.length; i++){
-            console.log(total);
             total += this._recipes[i].recipe.getIngredientTotalBase(ingredient.id) * this._recipes[i].quantity;
-            console.log(total);
         }
 
         return total;

+ 5 - 1
views/dashboardPage/js/sidebars/newRecipe.js

@@ -71,7 +71,11 @@ let newRecipe = {
                 unit: ingredients[i].children[1].children[1].value
             }
     
-            if(ingredient.getPotentialUnits().includes(newIngredient.unit) === false) mismatchUnits.push({ingredient: ingredient, newIngredient: newIngredient});
+            if(ingredient.getPotentialUnits().includes(newIngredient.unit) === false){
+                mismatchUnits.push({ingredient: ingredient, newIngredient: newIngredient});
+            }else{
+                newIngredient.baseUnitMultiplier = 1 / controller.baseUnit(1, newIngredient.unit);
+            }
     
             data.ingredients.push(newIngredient);
         }