diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index eccd940d..961a064d 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -30,6 +30,7 @@ _- (Because the stock quantity unit is now the base for everything, it cannot be ### Stock improvements/fixes - When creating a quantity unit conversion it's now possible to automatically create the inverse conversion (thanks @kriddles) +- On purchase there is now a warning shown, when the best before date of the purchased product is earlier than the next best before date in stock (enabled by default, can be disabled by a new stock setting (top right corner settings menu)) - Optimized/clarified what the total/unit price is on the purchase page (thanks @kriddles) - On the purchase page the amount field is now displayed above/before the best before date for better `TAB` handling (thanks @kriddles) - Changed that when `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` is disabled, products now get internally a best before of "never expires" (aka `2999-12-31`) instead of today (thanks @kriddles) diff --git a/config-dist.php b/config-dist.php index 1c5f0c32..ffc69de2 100644 --- a/config-dist.php +++ b/config-dist.php @@ -120,6 +120,7 @@ DefaultUserSetting('scan_mode_consume_enabled', false); DefaultUserSetting('scan_mode_purchase_enabled', false); DefaultUserSetting('show_icon_on_stock_overview_page_when_product_is_on_shopping_list', true); DefaultUserSetting('show_purchased_date_on_purchase', false); // Wheter the purchased date should be editable on purchase (defaults to today otherwise) +DefaultUserSetting('show_warning_on_purchase_when_best_before_date_is_earlier_than_next', true); // Show a warning on purchase when the best before date of the purchased product is earlier than the next best before date in stock // Shopping list settings DefaultUserSetting('shopping_list_to_stock_workflow_auto_submit_when_prefilled', false); // Automatically do the booking using the last price and the amount of the shopping list item, if the product has "Default best before days" set diff --git a/localization/strings.pot b/localization/strings.pot index 1325037d..2559fea6 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1924,3 +1924,9 @@ msgstr "" msgid "This is the default quantity unit used when adding this product to the shopping list" msgstr "" + +msgid "Show a warning when the best before date of the purchased product is earlier than the next best before date in stock" +msgstr "" + +msgid "There are items in stock which expire earlier" +msgstr "" diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index ba9424e3..2ca2745e 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -1,4 +1,6 @@ -$('#save-purchase-button').on('click', function(e) +var CurrentProductDetails; + +$('#save-purchase-button').on('click', function(e) { e.preventDefault(); @@ -97,6 +99,14 @@ toastr.success(successMessage); Grocy.Components.ProductPicker.FinishFlow(); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING && BoolVal(Grocy.UserSettings.show_warning_on_purchase_when_best_before_date_is_earlier_than_next)) + { + if (moment(jsonData.best_before_date).isBefore(CurrentProductDetails.next_best_before_date)) + { + toastr.warning(__t("There are items in stock which expire earlier")); + } + } + Grocy.Components.ProductAmountPicker.Reset(); $("#display_amount").attr("min", "1"); $("#display_amount").attr("step", "1"); @@ -162,6 +172,8 @@ if (Grocy.Components.ProductPicker !== undefined) Grocy.Api.Get('stock/products/' + productId, function(productDetails) { + CurrentProductDetails = productDetails; + Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.default_quantity_unit_purchase.id); $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts })); diff --git a/public/viewjs/stocksettings.js b/public/viewjs/stocksettings.js index 9d355bcf..48497f43 100644 --- a/public/viewjs/stocksettings.js +++ b/public/viewjs/stocksettings.js @@ -15,3 +15,8 @@ if (BoolVal(Grocy.UserSettings.show_purchased_date_on_purchase)) { $("#show_purchased_date_on_purchase").prop("checked", true); } + +if (BoolVal(Grocy.UserSettings.show_warning_on_purchase_when_best_before_date_is_earlier_than_next)) +{ + $("#show_warning_on_purchase_when_best_before_date_is_earlier_than_next").prop("checked", true); +} diff --git a/views/stocksettings.blade.php b/views/stocksettings.blade.php index 705a8380..1b296599 100644 --- a/views/stocksettings.blade.php +++ b/views/stocksettings.blade.php @@ -104,6 +104,19 @@ +
+
+ + +
+
+

{{ $__t('Consume') }}

@include('components.numberpicker', array( 'id' => 'stock_default_consume_amount',