Show a warning on purchase when purchased best before date is < in stock (closes #948)

This commit is contained in:
Bernd Bestel 2020-11-14 23:15:34 +01:00
parent db5c9ce3e8
commit f85b89d4fa
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
6 changed files with 39 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 ""

View File

@ -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 }));

View File

@ -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);
}

View File

@ -104,6 +104,19 @@
</div>
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox"
class="form-check-input custom-control-input user-setting-control"
id="show_warning_on_purchase_when_best_before_date_is_earlier_than_next"
data-setting-key="show_warning_on_purchase_when_best_before_date_is_earlier_than_next">
<label class="form-check-label custom-control-label"
for="show_warning_on_purchase_when_best_before_date_is_earlier_than_next">
{{ $__t('Show a warning when the best before date of the purchased product is earlier than the next best before date in stock') }}
</label>
</div>
</div>
<h4 class="mt-2">{{ $__t('Consume') }}</h4>
@include('components.numberpicker', array(
'id' => 'stock_default_consume_amount',