diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index cb1a56fb..323c0688 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -47,6 +47,7 @@ - Calories are now always displayed per single serving (on the recipe and meal plan page) - Fixed that "Only check if any amount is in stock" (recipe ingredient option) didn't work for stock amounts < 1 - Fixed that when adding missing items to the shopping list, on the popup deselected items got also added +- Fixed that the amount of self produced products with tare weight handling enabled was wrong ("Produces product" recipe option) ### Chores fixes - Fixed that tracking chores with "Done by" a different user was not possible diff --git a/services/RecipesService.php b/services/RecipesService.php index 856009d5..4dd38496 100644 --- a/services/RecipesService.php +++ b/services/RecipesService.php @@ -66,7 +66,7 @@ class RecipesService extends BaseService if (!empty($recipeRow->product_id)) { $recipeResolvedRow = $this->getDatabase()->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch(); - $this->getStockService()->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs)); + $this->getStockService()->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs), null, null, $dummyTransactionId, 0, true); } } diff --git a/services/StockService.php b/services/StockService.php index f7777371..2300c454 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -113,7 +113,7 @@ class StockService extends BaseService } } - public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = 0) + public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = 0, $addExactAmount = false) { if (!$this->ProductExists($productId)) { @@ -127,6 +127,11 @@ class StockService extends BaseService // The amount to be posted needs to be the given amount - stock amount - tare weight if ($productDetails->product->enable_tare_weight_handling == 1) { + if ($addExactAmount) + { + $amount = floatval($productDetails->stock_amount) + floatval($productDetails->product->tare_weight) + $amount; + } + if ($amount <= floatval($productDetails->product->tare_weight) + floatval($productDetails->stock_amount)) { throw new \Exception('The amount cannot be lower or equal than the defined tare weight + current stock amount');