Fixed missing recipe ingredient amount when "Only check if any amount is in stock" is enabled and when there are unit conversions (fixes #1718)

This commit is contained in:
Bernd Bestel
2022-01-23 13:56:41 +01:00
parent 49f44d241b
commit dfd6262f4a
3 changed files with 120 additions and 0 deletions

View File

@@ -36,6 +36,18 @@ class RecipesService extends BaseService
$toOrderAmount = round($recipePosition->missing_amount, 2);
}
// When the recipe ingredient option "Only check if any amount is in stock" is enabled,
// any QU can be used and the amount is not based on qu_stock then
// => Do the unit conversion here (if any)
if ($recipePosition->only_check_single_unit_in_stock == 1)
{
$conversion = $this->getDatabase()->quantity_unit_conversions_resolved()->where('product_id = :1 AND from_qu_id = :2 AND to_qu_id = :3', $recipePosition->product_id, $recipePosition->qu_id, $product->qu_id_stock)->fetch();
if ($conversion != null)
{
$toOrderAmount = $toOrderAmount * floatval($conversion->factor);
}
}
if ($toOrderAmount > 0)
{
$note = $this->getLocalizationService()->__t('Added for recipe %s', $recipe->name);