From 7200f2c17f8987842094a905127482c17eb74745 Mon Sep 17 00:00:00 2001 From: Mik- Date: Thu, 2 Apr 2020 08:34:43 +0200 Subject: [PATCH] Fix errors with disabled feature flag STOCK_PRICE_TRACKING (#687) fixes #685 --- public/viewjs/inventory.js | 12 +++++++++--- public/viewjs/purchase.js | 24 +++++++++++++++--------- public/viewjs/stockentryform.js | 4 +++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index 8286b308..72dc2e82 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -17,7 +17,9 @@ var jsonData = { }; jsonData.new_amount = jsonForm.new_amount; jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); - jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + } if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { jsonData.location_id = Grocy.Components.LocationPicker.GetValue(); @@ -85,7 +87,9 @@ $('#price').val(''); Grocy.Components.DateTimePicker.Clear(); Grocy.Components.ProductPicker.SetValue(''); - Grocy.Components.ShoppingLocationPicker.SetValue(''); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + Grocy.Components.ShoppingLocationPicker.SetValue(''); + } Grocy.Components.ProductPicker.GetInputElement().focus(); Grocy.Components.ProductCard.Refresh(jsonForm.product_id); Grocy.FrontendHelpers.ValidateForm('inventory-form'); @@ -152,7 +156,9 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) } $('#price').val(productDetails.last_price); - Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); + } if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { Grocy.Components.LocationPicker.SetId(productDetails.location.id); diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index e4e8e3b3..e1ee287b 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -29,7 +29,9 @@ var jsonData = {}; jsonData.amount = amount; jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); - jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + } jsonData.price = price; if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { @@ -100,7 +102,9 @@ } Grocy.Components.DateTimePicker.Clear(); Grocy.Components.ProductPicker.SetValue(''); - Grocy.Components.ShoppingLocationPicker.SetValue(''); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + Grocy.Components.ShoppingLocationPicker.SetValue(''); + } Grocy.Components.ProductPicker.GetInputElement().focus(); Grocy.Components.ProductCard.Refresh(jsonForm.product_id); Grocy.FrontendHelpers.ValidateForm('purchase-form'); @@ -141,13 +145,15 @@ if (Grocy.Components.ProductPicker !== undefined) { $('#price').val(productDetails.last_price); - if (productDetails.last_shopping_location_id != null) - { - Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); - } - else - { - Grocy.Components.ShoppingLocationPicker.SetId(productDetails.default_shopping_location_id); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + if (productDetails.last_shopping_location_id != null) + { + Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); + } + else + { + Grocy.Components.ShoppingLocationPicker.SetId(productDetails.default_shopping_location_id); + } } if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) diff --git a/public/viewjs/stockentryform.js b/public/viewjs/stockentryform.js index 4c50e0df..19817541 100644 --- a/public/viewjs/stockentryform.js +++ b/public/viewjs/stockentryform.js @@ -14,7 +14,9 @@ jsonData.amount = jsonForm.amount; jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); jsonData.purchased_date = Grocy.Components.DateTimePicker2.GetValue(); - jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { + jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); + } if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { jsonData.location_id = Grocy.Components.LocationPicker.GetValue();