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
4 changed files with 21 additions and 16 deletions

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