Optimized recipe missing ingredients shopping list item handling (closes #1890, closes #2134)

This commit is contained in:
Bernd Bestel 2025-01-19 21:31:36 +01:00
parent 0ff5aee6f6
commit ef9413c5c1
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 21 additions and 16 deletions

View File

@ -52,7 +52,10 @@
- Added a new recipe ingredient option "Round up quantity amounts to the nearest whole number"
- When enabled, resulting quantity amounts (after scaling according the desired serving amount) are always rounded up to the nearest whole number
- Defaults to disabled, so no changed behavior when not configured
- Optimized that when adding missing recipe ingredients with the option "Only check if any amount is in stock" enabled to the shopping list and when no corresponding unit conversion exists, the amount/unit is now taken "as is" (as defined in the recipe ingredient) into the created shopping list item
- Optimizations/changes when adding missing recipe ingredients to the shopping list:
- When the ingredient option "Only check if any amount is in stock" is enabled and when no corresponding unit conversion exists, the amount/unit is now taken "as is" (as defined in the recipe ingredient) into the created shopping list item
- The shopping list item no longer gets a note "Added for recipe" set and the ingredient note is no longer appended
- When the corresponding product is already on the shopping list, the amount of the existing item is incremented instead of creating a new shopping list item
- When no price information is available for at least one ingredient, a red exclamation mark is now displayed next to the recipe total cost information
- Fixed that calories/costs of recipe ingredients were wrong when the ingredient option "Only check if any amount is in stock" was set and the on the ingredient used quantity unit was different from the product's QU stock
- Fixed that multi-nested recipes (at least 3 levels of "included recipes") resulted in wrong amounts/costs/calories calculated for the ingredients orginating in those nested recipes (also affected the meal plan)

View File

@ -476,9 +476,6 @@ msgstr ""
msgid "Are you sure you want to put all missing ingredients for recipe \"%s\" on the shopping list?"
msgstr ""
msgid "Added for recipe %s"
msgstr ""
msgid "Manage users"
msgstr ""

View File

@ -46,6 +46,7 @@ class RecipesService extends BaseService
}
else
{
// No conversion exists => take the amount/unit as is
$quId = $recipePosition->qu_id;
$toOrderAmount = $recipePosition->missing_amount;
}
@ -53,19 +54,24 @@ class RecipesService extends BaseService
if ($toOrderAmount > 0)
{
$note = $this->getLocalizationService()->__t('Added for recipe %s', $recipe->name);
if (!empty($recipePosition->note))
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $recipePosition->product_id)->fetch();
if ($alreadyExistingEntry)
{
$note .= "\n" . $recipePosition->note;
// Update
$alreadyExistingEntry->update([
'amount' => $alreadyExistingEntry->amount + $toOrderAmount
]);
}
else
{
// Insert
$shoppinglistRow = $this->getDataBase()->shopping_list()->createRow([
'product_id' => $recipePosition->product_id,
'amount' => $toOrderAmount,
'qu_id' => $quId
]);
$shoppinglistRow->save();
}
$shoppinglistRow = $this->getDataBase()->shopping_list()->createRow([
'product_id' => $recipePosition->product_id,
'amount' => $toOrderAmount,
'qu_id' => $quId,
'note' => $note
]);
$shoppinglistRow->save();
}
}
}

View File

@ -32,7 +32,6 @@ class StockService extends BaseService
$amountToAdd = round($missingProduct->amount_missing, 2);
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $missingProduct->id)->fetch();
if ($alreadyExistingEntry)
{
// Update