mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Fixed produces product amount handling when consuming meal plan shadow recipes (references #2160)
This commit is contained in:
parent
792c710bdc
commit
6857796ef0
@ -271,7 +271,7 @@ class ChoresService extends BaseService
|
||||
$this->getDatabaseService()->ExecuteDbStatement('UPDATE chores_log SET chore_id = ' . $choreIdToKeep . ' WHERE chore_id = ' . $choreIdToRemove);
|
||||
$this->getDatabaseService()->ExecuteDbStatement('DELETE FROM chores WHERE id = ' . $choreIdToRemove);
|
||||
}
|
||||
catch (Exception $ex)
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
|
@ -74,7 +74,7 @@ class DatabaseMigrationService extends BaseService
|
||||
$migrationCounter++;
|
||||
}
|
||||
}
|
||||
catch (Exception $ex)
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
|
@ -94,7 +94,7 @@ class RecipesService extends BaseService
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $ex)
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
@ -103,18 +103,21 @@ class RecipesService extends BaseService
|
||||
|
||||
$recipe = $this->getDatabase()->recipes()->where('id = :1', $recipeId)->fetch();
|
||||
$productId = $recipe->product_id;
|
||||
$amount = $recipe->desired_servings;
|
||||
if ($recipe->type == self::RECIPE_TYPE_MEALPLAN_SHADOW)
|
||||
{
|
||||
// Use "Produces product" of the original recipe
|
||||
$mealPlanEntry = $this->getDatabase()->meal_plan()->where('id = :1', explode('#', $recipe->name)[1])->fetch();
|
||||
$productId = $this->getDatabase()->recipes()->where('id = :1', $mealPlanEntry->recipe_id)->fetch()->product_id;
|
||||
$recipe = $this->getDatabase()->recipes()->where('id = :1', $mealPlanEntry->recipe_id)->fetch();
|
||||
$productId = $recipe->product_id;
|
||||
$amount = $mealPlanEntry->recipe_servings;
|
||||
}
|
||||
|
||||
if (!empty($productId))
|
||||
{
|
||||
$product = $this->getDatabase()->products()->where('id = :1', $productId)->fetch();
|
||||
$recipeResolvedRow = $this->getDatabase()->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch();
|
||||
$this->getStockService()->AddProduct($productId, $recipe->desired_servings, null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), $recipeResolvedRow->costs_per_serving, null, null, $dummyTransactionId, $product->default_stock_label_type, true);
|
||||
$this->getStockService()->AddProduct($productId, $amount, null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), $recipeResolvedRow->costs_per_serving, null, null, $dummyTransactionId, $product->default_stock_label_type, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1702,7 +1702,7 @@ class StockService extends BaseService
|
||||
$this->getDatabaseService()->ExecuteDbStatement('UPDATE shopping_list SET product_id = ' . $productIdToKeep . ', amount = amount * ' . $factor . ' WHERE product_id = ' . $productIdToRemove);
|
||||
$this->getDatabaseService()->ExecuteDbStatement('DELETE FROM products WHERE id = ' . $productIdToRemove);
|
||||
}
|
||||
catch (Exception $ex)
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
@ -1749,7 +1749,7 @@ class StockService extends BaseService
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $ex)
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user