Skip to content
Snippets Groups Projects

When adding recipe items to shopping list the recipe unit is converted to unit...

Merged Axel Ytterås requested to merge AddToShoppingListFromRecipeConvertAmountFix into main
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
@@ -322,7 +322,7 @@ public class ShoppingListService {
@@ -322,7 +322,7 @@ public class ShoppingListService {
ShoppingList shoppingList = shoppingListRepository.findById(loggedInAccount.getShoppingList().getId()).get();
ShoppingList shoppingList = shoppingListRepository.findById(loggedInAccount.getShoppingList().getId()).get();
recipe.getIngredient().forEach(ingredient -> {
recipe.getIngredient().forEach(ingredient -> {
double itemAmount = ingredient.getItem().getAmount().getQuantity();
double itemAmount = ingredient.getItem().getAmount().getQuantity();
double ingredientAmount = ingredient.getAmount().getQuantity()*peopleCount;
double ingredientAmount = ingredient.getAmount().deserialize().convertTo(ingredient.getItem().getAmount().deserialize().getUnit()).getQuantity()*peopleCount;
double amountOfItemInFridge = getAmountOfItemFromFridge(ingredient.getItem(),loggedInAccount);
double amountOfItemInFridge = getAmountOfItemFromFridge(ingredient.getItem(),loggedInAccount);
double ingredientAmountNotOwned = ingredientAmount - amountOfItemInFridge;
double ingredientAmountNotOwned = ingredientAmount - amountOfItemInFridge;
double ingredientAmountToReserve = Math.min(ingredientAmount, amountOfItemInFridge);
double ingredientAmountToReserve = Math.min(ingredientAmount, amountOfItemInFridge);
@@ -332,7 +332,7 @@ public class ShoppingListService {
@@ -332,7 +332,7 @@ public class ShoppingListService {
}
}
double quantityToAddOfWare = ingredientAmountNotOwned/itemAmount;
double quantityToAddOfWare = ingredientAmountNotOwned/itemAmount;
if (quantityToAddOfWare > 0) {
if (quantityToAddOfWare > 0) {
Ingredient shoppingListIngredient = new Ingredient(ingredient.getItem(), new SerializedAmount(Math.ceil(quantityToAddOfWare), ingredient.getItem().getAmount().getUnit()));
Ingredient shoppingListIngredient = new Ingredient(ingredient.getItem(), new Amount(Math.ceil(quantityToAddOfWare), Count.COUNT).serialize());
shoppingListIngredient.setStatus(Ingredient.Status.REQUESTED);
shoppingListIngredient.setStatus(Ingredient.Status.REQUESTED);
ingredientRepository.save(shoppingListIngredient);
ingredientRepository.save(shoppingListIngredient);
shoppingList.addIngredient(shoppingListIngredient);
shoppingList.addIngredient(shoppingListIngredient);
Loading