diff --git a/localization/en/stock_transaction_types.po b/localization/en/stock_transaction_types.po index d8b65ef1..621fbfe1 100644 --- a/localization/en/stock_transaction_types.po +++ b/localization/en/stock_transaction_types.po @@ -35,3 +35,6 @@ msgstr "Stock entry edited (old values)" msgid "stock-edit-new" msgstr "Stock entry edited (new values)" + +msgid "self-production" +msgstr "Self-production" diff --git a/localization/stock_transaction_types.pot b/localization/stock_transaction_types.pot index 48930d28..09f11fba 100644 --- a/localization/stock_transaction_types.pot +++ b/localization/stock_transaction_types.pot @@ -35,3 +35,6 @@ msgstr "" msgid "stock-edit-new" msgstr "" + +msgid "self-production" +msgstr "" diff --git a/localization/strings.pot b/localization/strings.pot index 2d9f91eb..32322721 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1618,3 +1618,12 @@ msgstr "" msgid "A purchased date is required" msgstr "" + +msgid "When a product is selected, one unit (per serving in purchase quantity unit) will be added to stock on consuming this recipe" +msgstr "" + +msgid "Produces product" +msgstr "" + +msgid "This booking cannot be undone" +msgstr "" diff --git a/migrations/0095.sql b/migrations/0095.sql index 94931be1..440638e6 100644 --- a/migrations/0095.sql +++ b/migrations/0095.sql @@ -20,6 +20,22 @@ ADD correlation_id TEXT; ALTER TABLE stock_log ADD transaction_id TEXT; +ALTER TABLE stock_log +ADD stock_row_id INTEGER; + +DROP VIEW stock_current_locations; +CREATE VIEW stock_current_locations +AS +SELECT + 1 AS id, -- Dummy, LessQL needs an id column + s.product_id, + s.location_id AS location_id, + l.name AS location_name +FROM stock s +JOIN locations l + ON s.location_id = l.id +GROUP BY s.product_id, s.location_id, l.name; + ALTER TABLE recipes ADD product_id INTEGER; @@ -38,19 +54,3 @@ FROM recipes r LEFT JOIN recipes_pos_resolved rpr ON r.id = rpr.recipe_id GROUP BY r.id; - -ALTER TABLE stock_log -ADD stock_row_id INTEGER; - -DROP VIEW stock_current_locations; -CREATE VIEW stock_current_locations -AS -SELECT - 1 AS id, -- Dummy, LessQL needs an id column - s.product_id, - s.location_id AS location_id, - l.name AS location_name -FROM stock s -JOIN locations l - ON s.location_id = l.id -GROUP BY s.product_id, s.location_id, l.name; diff --git a/public/viewjs/recipeform.js b/public/viewjs/recipeform.js index fcd50bd6..4bf417bd 100644 --- a/public/viewjs/recipeform.js +++ b/public/viewjs/recipeform.js @@ -1,8 +1,4 @@ -$(document).ready(function() { - Grocy.Components.ProductPicker.GetPicker().trigger('change'); -} ); - -$('#save-recipe-button').on('click', function(e) +$('#save-recipe-button').on('click', function(e) { e.preventDefault(); @@ -351,15 +347,4 @@ $(window).on("message", function(e) { window.location.href = U('/recipe/' + Grocy.EditObjectId); } - -}); - -Grocy.Components.ProductPicker.GetPicker().on('change', function(e) -{ - var productId = $(e.target).val(); - - if (productId) - { - Grocy.Components.ProductCard.Refresh(productId); - } }); diff --git a/services/RecipesService.php b/services/RecipesService.php index 85d1a9c8..c9c070f2 100644 --- a/services/RecipesService.php +++ b/services/RecipesService.php @@ -67,15 +67,6 @@ class RecipesService extends BaseService throw new \Exception('Recipe does not exist'); } - $recipeRow = $this->Database->recipes()->where('id = :1', $recipeId)->fetch(); - if ($recipeRow->product_id != null) - { - $recipeResolvedRow = $this->Database->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch(); - $price = number_format($recipeResolvedRow->costs, 2); - $bookingAmount = floatval($recipeRow->desired_servings); - $this->StockService->AddProduct($recipeRow->product_id, $bookingAmount, null, StockService::TRANSACTION_TYPE_PURCHASE, date('Y-m-d'), $price); - } - $recipePositions = $this->Database->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll(); foreach ($recipePositions as $recipePosition) { @@ -84,6 +75,13 @@ class RecipesService extends BaseService $this->StockService->ConsumeProduct($recipePosition->product_id, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId); } } + + $recipeRow = $this->Database->recipes()->where('id = :1', $recipeId)->fetch(); + if (!empty($recipeRow->product_id)) + { + $recipeResolvedRow = $this->Database->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch(); + $this->StockService->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs)); + } } private function RecipeExists($recipeId) diff --git a/services/StockService.php b/services/StockService.php index 79d8cf3e..c4b43faf 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -12,6 +12,7 @@ class StockService extends BaseService const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new'; const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old'; const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened'; + const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production'; public function GetCurrentStock($includeNotInStockButMissingProducts = false) { @@ -242,7 +243,7 @@ class StockService extends BaseService } } - if ($transactionType === self::TRANSACTION_TYPE_PURCHASE || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION) + if ($transactionType === self::TRANSACTION_TYPE_PURCHASE || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION || $transactionType == self::TRANSACTION_TYPE_SELF_PRODUCTION) { if ($transactionId === null) { diff --git a/views/recipeform.blade.php b/views/recipeform.blade.php index f7c3b782..75b0efd3 100644 --- a/views/recipeform.blade.php +++ b/views/recipeform.blade.php @@ -61,13 +61,7 @@ 'value' => $value, 'invalidFeedback' => $__t('This cannot be lower than %s', '1'), 'hint' => $__t('The ingredients listed here result in this amount of servings') - )) - - @include('components.productpicker', array( - 'products' => $products, - 'isRequired' => false, - 'label' => 'Creates Product' - )) + ))
@@ -89,6 +83,15 @@
+ @include('components.productpicker', array( + 'products' => $products, + 'isRequired' => false, + 'label' => 'Produces product', + 'prefillById' => $recipe->product_id, + 'disallowAllProductWorkflows' => true, + 'hint' => $__t('When a product is selected, one unit (per serving in purchase quantity unit) will be added to stock on consuming this recipe') + )) + @include('components.userfieldsform', array( 'userfields' => $userfields, 'entity' => 'recipes' @@ -222,11 +225,6 @@ @endif -
-
- @include('components.productcard') -
-
diff --git a/views/recipes.blade.php b/views/recipes.blade.php index 1a5de6e7..47f9058b 100644 --- a/views/recipes.blade.php +++ b/views/recipes.blade.php @@ -137,7 +137,7 @@    - +