Explorar el Código

Bug fix: recipes were not being properly added to the merchant. The format was wrong.

Lee Morgan hace 5 años
padre
commit
02de58e777

+ 14 - 5
controllers/recipeData.js

@@ -359,7 +359,9 @@ module.exports = {
                     ingredients.push({
                         id: merchant.inventory[i].ingredient._id,
                         name: merchant.inventory[i].ingredient.name.toLowerCase(),
-                        unit: merchant.inventory[i].defaultUnit
+                        unit: merchant.inventory[i].defaultUnit,
+                        specialUnit: merchant.inventory[i].specialUnit,
+                        unitSize: merchant.inventory[i].unitSize
                     });
                 }
 
@@ -384,10 +386,17 @@ module.exports = {
                     let exists = false;
                     for(let j = 0; j < ingredients.length; j++){
                         if(ingredients[j].name === array[i][locations.ingredient]){
-                            currentRecipe.ingredients.push({
-                                ingredient: ingredients[j].id,
-                                quantity: helper.convertQuantityToBaseUnit(array[i][locations.amount], ingredients[j].unit)
-                            });
+                            if(ingrediens[j].specialUnit = "bottle"){
+                                currentRecipe.ingredients.push({
+                                    ingredient: ingredients[j].id,
+                                    quantity: array[i][locations.amount]
+                                });
+                            }else{
+                                currentRecipe.ingredients.push({
+                                    ingredient: ingredients[j].id,
+                                    quantity: helper.convertQuantityToBaseUnit(array[i][locations.amount], ingredients[j].unit)
+                                });
+                            }
 
                             exists = true;
                             break;

+ 9 - 5
views/dashboardPage/bundle.js

@@ -1078,10 +1078,8 @@ class RecipeIngredient{
 
     getQuantityDisplay(){
         if(this._ingredient.specialUnit === "bottle"){
-            
             return `${this.quantity.toFixed(2)} BOTTLES`;
         }
-
         return `${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`;
     }
 
@@ -1293,7 +1291,13 @@ class Transaction{
             const recipe = this._recipes[i].recipe;
             for(let j = 0; j < recipe.ingredients.length; j++){
                 if(recipe.ingredients[j].ingredient === ingredient){
+                    if(recipe.ingredients[j].ingredient.specialUnit === "bottle"){
+                        let thing = recipe.ingredients[j]._quantity * recipe.ingredients[j].ingredient._unitSize * this._recipes[i]._quantity;
+                        quantity += thing;
+                    }
+
                     quantity += recipe.ingredients[j].quantity * this._recipes[i].quantity;
+                    break;
                 }
             }
         }
@@ -2400,7 +2404,7 @@ let newRecipe = {
                         for(let j = 0; j < merchant.ingredients.length; j++){
                             if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
                                 ingredients.push({
-                                    ingredient: merchant.ingredients[j].ingredient,
+                                    ingredient: merchant.ingredients[j].ingredient.id,
                                     quantity: response.ingredients[i].quantity
                                 });
 
@@ -3207,8 +3211,8 @@ let analytics = {
 
             let sum = 0;
             for(let j = 0; j < this.transactionsByDate[i].transactions.length; j++){
-                let transactions = this.transactionsByDate[i].transactions[j];
-                sum += transactions.getIngredientQuantity(this.ingredient);
+                let transaction = this.transactionsByDate[i].transactions[j];
+                sum += transaction.getIngredientQuantity(this.ingredient);
             }
             
             quantities.push(sum);

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

@@ -51,10 +51,8 @@ class RecipeIngredient{
 
     getQuantityDisplay(){
         if(this._ingredient.specialUnit === "bottle"){
-            
             return `${this.quantity.toFixed(2)} BOTTLES`;
         }
-
         return `${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`;
     }
 

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

@@ -75,7 +75,13 @@ class Transaction{
             const recipe = this._recipes[i].recipe;
             for(let j = 0; j < recipe.ingredients.length; j++){
                 if(recipe.ingredients[j].ingredient === ingredient){
+                    if(recipe.ingredients[j].ingredient.specialUnit === "bottle"){
+                        let thing = recipe.ingredients[j]._quantity * recipe.ingredients[j].ingredient._unitSize * this._recipes[i]._quantity;
+                        quantity += thing;
+                    }
+
                     quantity += recipe.ingredients[j].quantity * this._recipes[i].quantity;
+                    break;
                 }
             }
         }

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

@@ -100,7 +100,7 @@ let newRecipe = {
                         for(let j = 0; j < merchant.ingredients.length; j++){
                             if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
                                 ingredients.push({
-                                    ingredient: merchant.ingredients[j].ingredient,
+                                    ingredient: merchant.ingredients[j].ingredient.id,
                                     quantity: response.ingredients[i].quantity
                                 });
 

+ 2 - 2
views/dashboardPage/js/strands/analytics.js

@@ -126,8 +126,8 @@ let analytics = {
 
             let sum = 0;
             for(let j = 0; j < this.transactionsByDate[i].transactions.length; j++){
-                let transactions = this.transactionsByDate[i].transactions[j];
-                sum += transactions.getIngredientQuantity(this.ingredient);
+                let transaction = this.transactionsByDate[i].transactions[j];
+                sum += transaction.getIngredientQuantity(this.ingredient);
             }
             
             quantities.push(sum);