Fixed that consuming partially fulfilled recipes was possible (fixes #1981)

This commit is contained in:
Bernd Bestel
2022-08-27 00:08:23 +02:00
parent c0d0b8fc90
commit f1bc2cc40f
3 changed files with 15 additions and 6 deletions

View File

@@ -66,3 +66,4 @@
- Endpoint `/stock/volatile`
- The field/property `missing_products` now also contains the `product` object
- Endpoint `/recipes/{recipeId}/consume`: Fixed (again) that consuming partially fulfilled recipes was possible, although an error was already returned in that case (and potentially some of the in stock ingredients were consumed in fact)

View File

@@ -81,8 +81,11 @@ class RecipesService extends BaseService
}
$transactionId = uniqid();
$recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
$this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction();
try
{
foreach ($recipePositions as $recipePosition)
{
if ($recipePosition->only_check_single_unit_in_stock == 0)
@@ -90,6 +93,13 @@ class RecipesService extends BaseService
$this->getStockService()->ConsumeProduct($recipePosition->product_id_effective, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId, null, $transactionId, true, true);
}
}
}
catch (Exception $ex)
{
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
throw $ex;
}
$this->getDatabaseService()->GetDbConnectionRaw()->commit();
$recipeRow = $this->getDatabase()->recipes()->where('id = :1', $recipeId)->fetch();
if (!empty($recipeRow->product_id))

View File

@@ -493,8 +493,6 @@ class StockService extends BaseService
}
}
$this->CompactStockEntries($productId);
if (boolval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'shopping_list_auto_add_below_min_stock_amount')))
{
$this->AddMissingProductsToShoppingList(intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'shopping_list_auto_add_below_min_stock_amount_list_id')));