Fixed self production amount was wrong for tare weight handling enabled products (fixes #1431)

This commit is contained in:
Bernd Bestel 2021-07-03 18:30:53 +02:00
parent 765ba77621
commit bcf963ac49
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 8 additions and 2 deletions

View File

@ -47,6 +47,7 @@
- Calories are now always displayed per single serving (on the recipe and meal plan page) - 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 "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 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 ### Chores fixes
- Fixed that tracking chores with "Done by" a different user was not possible - Fixed that tracking chores with "Done by" a different user was not possible

View File

@ -66,7 +66,7 @@ class RecipesService extends BaseService
if (!empty($recipeRow->product_id)) if (!empty($recipeRow->product_id))
{ {
$recipeResolvedRow = $this->getDatabase()->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch(); $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);
} }
} }

View File

@ -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)) 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 // The amount to be posted needs to be the given amount - stock amount - tare weight
if ($productDetails->product->enable_tare_weight_handling == 1) 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)) 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'); throw new \Exception('The amount cannot be lower or equal than the defined tare weight + current stock amount');