diff --git a/changelog/52_UNRELEASED_2019-xx-xx.md b/changelog/52_UNRELEASED_2019-xx-xx.md
index 0209edae..7b875783 100644
--- a/changelog/52_UNRELEASED_2019-xx-xx.md
+++ b/changelog/52_UNRELEASED_2019-xx-xx.md
@@ -31,6 +31,8 @@
### Recipe improvements
- Based on the new linked quantity units, recipe ingredients can now use any product related unit, the amount is calculated according to the cnoversion factor of the unit relation
+- New option "price factor" per recipe ingredient (defaults to `1`) - the resulting costs of the recipe ingredient will be multiplied by that factor
+ - Use this for example for spices in combination with "Only check if a single unit is in stock" to not take the full price of a pack of pepper into account for a recipe
### Chores improvements
- Chores can now be assigned to users
diff --git a/localization/strings.pot b/localization/strings.pot
index 2cdb61e5..7f5e2b04 100644
--- a/localization/strings.pot
+++ b/localization/strings.pot
@@ -1468,3 +1468,9 @@ msgstr ""
msgid "Error while initializing the barcode scanning library"
msgstr ""
+
+msgid "The resulting price of this ingredient will be multiplied by this factor"
+msgstr ""
+
+msgid "Price factor"
+msgstr ""
diff --git a/migrations/0087.sql b/migrations/0087.sql
new file mode 100644
index 00000000..3c928343
--- /dev/null
+++ b/migrations/0087.sql
@@ -0,0 +1,90 @@
+ALTER TABLE recipes_pos
+ADD price_factor REAL NOT NULL DEFAULT 1;
+
+DROP VIEW recipes_pos_resolved;
+CREATE VIEW recipes_pos_resolved
+AS
+
+-- Multiplication by 1.0 to force conversion to float (REAL)
+
+SELECT
+ r.id AS recipe_id,
+ rp.id AS recipe_pos_id,
+ rp.product_id AS product_id,
+ rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) AS recipe_amount,
+ IFNULL(sc.amount_aggregated, 0) AS stock_amount,
+ CASE WHEN IFNULL(sc.amount_aggregated, 0) >= CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END THEN 1 ELSE 0 END AS need_fulfilled,
+ CASE WHEN IFNULL(sc.amount_aggregated, 0) - CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END < 0 THEN ABS(IFNULL(sc.amount_aggregated, 0) - (CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END)) ELSE 0 END AS missing_amount,
+ IFNULL(sl.amount, 0) * p.qu_factor_purchase_to_stock AS amount_on_shopping_list,
+ CASE WHEN IFNULL(sc.amount_aggregated, 0) + (CASE WHEN r.not_check_shoppinglist = 1 THEN 0 ELSE IFNULL(sl.amount, 0) END * p.qu_factor_purchase_to_stock) >= CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END THEN 1 ELSE 0 END AS need_fulfilled_with_shopping_list,
+ rp.qu_id,
+ (CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END / p.qu_factor_purchase_to_stock) * pcp.last_price * rp.price_factor AS costs,
+ CASE WHEN rnr.recipe_id = rnr.includes_recipe_id THEN 0 ELSE 1 END AS is_nested_recipe_pos,
+ rp.ingredient_group,
+ rp.id, -- Just a dummy id column
+ rnr.includes_recipe_id as child_recipe_id,
+ rp.note,
+ rp.variable_amount AS recipe_variable_amount,
+ rp.only_check_single_unit_in_stock
+FROM recipes r
+JOIN recipes_nestings_resolved rnr
+ ON r.id = rnr.recipe_id
+JOIN recipes rnrr
+ ON rnr.includes_recipe_id = rnrr.id
+JOIN recipes_pos rp
+ ON rnr.includes_recipe_id = rp.recipe_id
+JOIN products p
+ ON rp.product_id = p.id
+LEFT JOIN (
+ SELECT product_id, SUM(amount) AS amount
+ FROM shopping_list
+ GROUP BY product_id) sl
+ ON rp.product_id = sl.product_id
+LEFT JOIN stock_current sc
+ ON rp.product_id = sc.product_id
+LEFT JOIN products_current_price pcp
+ ON rp.product_id = pcp.product_id
+WHERE rp.not_check_stock_fulfillment = 0
+
+UNION
+
+-- Just add all recipe positions which should not be checked against stock with fulfilled need
+
+SELECT
+ r.id AS recipe_id,
+ rp.id AS recipe_pos_id,
+ rp.product_id AS product_id,
+ rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) AS recipe_amount,
+ IFNULL(sc.amount_aggregated, 0) AS stock_amount,
+ 1 AS need_fulfilled,
+ 0 AS missing_amount,
+ IFNULL(sl.amount, 0) * p.qu_factor_purchase_to_stock AS amount_on_shopping_list,
+ 1 AS need_fulfilled_with_shopping_list,
+ rp.qu_id,
+ (CASE WHEN rp.only_check_single_unit_in_stock = 1 THEN 1 ELSE rp.amount * (r.desired_servings*1.0 / r.base_servings*1.0) * (rnr.includes_servings*1.0 / CASE WHEN rnr.recipe_id != rnr.includes_recipe_id THEN rnrr.base_servings*1.0 ELSE 1 END) END / p.qu_factor_purchase_to_stock) * pcp.last_price * rp.price_factor AS costs,
+ CASE WHEN rnr.recipe_id = rnr.includes_recipe_id THEN 0 ELSE 1 END AS is_nested_recipe_pos,
+ rp.ingredient_group,
+ rp.id, -- Just a dummy id column
+ rnr.includes_recipe_id as child_recipe_id,
+ rp.note,
+ rp.variable_amount AS recipe_variable_amount,
+ rp.only_check_single_unit_in_stock
+FROM recipes r
+JOIN recipes_nestings_resolved rnr
+ ON r.id = rnr.recipe_id
+JOIN recipes rnrr
+ ON rnr.includes_recipe_id = rnrr.id
+JOIN recipes_pos rp
+ ON rnr.includes_recipe_id = rp.recipe_id
+JOIN products p
+ ON rp.product_id = p.id
+LEFT JOIN (
+ SELECT product_id, SUM(amount) AS amount
+ FROM shopping_list
+ GROUP BY product_id) sl
+ ON rp.product_id = sl.product_id
+LEFT JOIN stock_current sc
+ ON rp.product_id = sc.product_id
+LEFT JOIN products_current_price pcp
+ ON rp.product_id = pcp.product_id
+WHERE rp.not_check_stock_fulfillment = 1;
diff --git a/views/recipeposform.blade.php b/views/recipeposform.blade.php
index a07dbfff..63c358fe 100644
--- a/views/recipeposform.blade.php
+++ b/views/recipeposform.blade.php
@@ -74,6 +74,23 @@
+ @if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
+ @php if($mode == 'edit') { $value = $recipePos->price_factor; } else { $value = 1; } @endphp
+ @include('components.numberpicker', array(
+ 'id' => 'price_factor',
+ 'label' => 'Price factor',
+ 'min' => 0,
+ 'step' => 0.0001,
+ 'value' => '',
+ 'hint' => $__t('The resulting price of this ingredient will be multiplied by this factor'),
+ 'invalidFeedback' => $__t('This cannot be lower than %s', '0'),
+ 'isRequired' => true,
+ 'value' => $value
+ ))
+ @else
+
+ @endif
+