mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Fixed that consuming partially fulfilled recipes was possible (fixes #1981)
This commit is contained in:
parent
c0d0b8fc90
commit
f1bc2cc40f
@ -66,3 +66,4 @@
|
|||||||
|
|
||||||
- Endpoint `/stock/volatile`
|
- Endpoint `/stock/volatile`
|
||||||
- The field/property `missing_products` now also contains the `product` object
|
- 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)
|
||||||
|
@ -81,15 +81,25 @@ class RecipesService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$transactionId = uniqid();
|
$transactionId = uniqid();
|
||||||
|
|
||||||
$recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
|
$recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
|
||||||
foreach ($recipePositions as $recipePosition)
|
|
||||||
|
$this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if ($recipePosition->only_check_single_unit_in_stock == 0)
|
foreach ($recipePositions as $recipePosition)
|
||||||
{
|
{
|
||||||
$this->getStockService()->ConsumeProduct($recipePosition->product_id_effective, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId, null, $transactionId, true, true);
|
if ($recipePosition->only_check_single_unit_in_stock == 0)
|
||||||
|
{
|
||||||
|
$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();
|
$recipeRow = $this->getDatabase()->recipes()->where('id = :1', $recipeId)->fetch();
|
||||||
if (!empty($recipeRow->product_id))
|
if (!empty($recipeRow->product_id))
|
||||||
|
@ -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')))
|
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')));
|
$this->AddMissingProductsToShoppingList(intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'shopping_list_auto_add_below_min_stock_amount_list_id')));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user