Use barcode defaults also for scan mode (fixes #1253)

This commit is contained in:
Bernd Bestel 2021-01-04 21:15:22 +01:00
parent 030939e013
commit d78e156609
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 29 additions and 20 deletions

View File

@ -1864,7 +1864,7 @@ msgstr ""
msgid "This is due earlier than already in-stock items" msgid "This is due earlier than already in-stock items"
msgstr "" msgstr ""
msgid "When enabled, the amount will always be filled with 1 after changing/scanning a product and if all fields could be automatically populated (by product defaults), the transaction is automatically submitted" msgid "When enabled, after changing/scanning a product and if all fields could be automatically populated (by product and/or barcode defaults), the transaction is automatically submitted"
msgstr "" msgstr ""
msgid "Quick consume amount" msgid "Quick consume amount"

View File

@ -287,23 +287,6 @@ if (Grocy.Components.ProductPicker !== undefined)
$("#save-purchase-button").click(); $("#save-purchase-button").click();
} }
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
$("#display_amount").val(1);
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm("purchase-form");
if (document.getElementById("purchase-form").checkValidity() === true)
{
$('#save-purchase-button').click();
}
else
{
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error();
}
}
RefreshLocaleNumberInput(); RefreshLocaleNumberInput();
if (document.getElementById("product_id").getAttribute("barcode") != "null") if (document.getElementById("product_id").getAttribute("barcode") != "null")
@ -345,6 +328,8 @@ if (Grocy.Components.ProductPicker !== undefined)
RefreshLocaleNumberInput(); RefreshLocaleNumberInput();
} }
} }
ScanModeSubmit(false);
}, },
function(xhr) function(xhr)
{ {
@ -355,6 +340,7 @@ if (Grocy.Components.ProductPicker !== undefined)
else else
{ {
$("#purchase-form").removeAttr("data-used-barcode"); $("#purchase-form").removeAttr("data-used-barcode");
ScanModeSubmit();
} }
$('#display_amount').trigger("keyup"); $('#display_amount').trigger("keyup");
@ -588,3 +574,26 @@ $('#qu_id').on('change', function(e)
priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price")); priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
refreshPriceHint(); refreshPriceHint();
}); });
function ScanModeSubmit(singleUnit = true)
{
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
if (singleUnit)
{
$("#display_amount").val(1);
$(".input-group-productamountpicker").trigger("change");
}
Grocy.FrontendHelpers.ValidateForm("purchase-form");
if (document.getElementById("purchase-form").checkValidity() === true)
{
$('#save-purchase-button').click();
}
else
{
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error();
}
}
}

View File

@ -31,7 +31,7 @@
<button id="scan-mode-button" <button id="scan-mode-button"
class="btn @if(boolval($userSettings['scan_mode_consume_enabled'])) btn-success @else btn-danger @endif m-1 mt-md-0 mb-md-0 float-right" class="btn @if(boolval($userSettings['scan_mode_consume_enabled'])) btn-success @else btn-danger @endif m-1 mt-md-0 mb-md-0 float-right"
data-toggle="tooltip" data-toggle="tooltip"
title="{{ $__t('When enabled, the amount will always be filled with 1 after changing/scanning a product and if all fields could be automatically populated (by product defaults), the transaction is automatically submitted') }}">{{ $__t('Scan mode') }} <span id="scan-mode-status">@if(boolval($userSettings['scan_mode_consume_enabled'])) {{ $__t('on') }} @else {{ $__t('off') }} @endif</span></button> title="{{ $__t('When enabled, after changing/scanning a product and if all fields could be automatically populated (by product and/or barcode defaults), the transaction is automatically submitted') }}">{{ $__t('Scan mode') }} <span id="scan-mode-status">@if(boolval($userSettings['scan_mode_consume_enabled'])) {{ $__t('on') }} @else {{ $__t('off') }} @endif</span></button>
<input id="scan-mode" <input id="scan-mode"
type="checkbox" type="checkbox"
class="d-none user-setting-control" class="d-none user-setting-control"

View File

@ -31,7 +31,7 @@
<button id="scan-mode-button" <button id="scan-mode-button"
class="btn @if(boolval($userSettings['scan_mode_purchase_enabled'])) btn-success @else btn-danger @endif m-1 mt-md-0 mb-md-0 float-right" class="btn @if(boolval($userSettings['scan_mode_purchase_enabled'])) btn-success @else btn-danger @endif m-1 mt-md-0 mb-md-0 float-right"
data-toggle="tooltip" data-toggle="tooltip"
title="{{ $__t('When enabled, the amount will always be filled with 1 after changing/scanning a product and if all fields could be automatically populated (by product defaults), the transaction is automatically submitted') }}">{{ $__t('Scan mode') }} <span id="scan-mode-status">@if(boolval($userSettings['scan_mode_purchase_enabled'])) {{ $__t('on') }} @else {{ $__t('off') }} @endif</span></button> title="{{ $__t('When enabled, after changing/scanning a product and if all fields could be automatically populated (by product and/or barcode defaults), the transaction is automatically submitted') }}">{{ $__t('Scan mode') }} <span id="scan-mode-status">@if(boolval($userSettings['scan_mode_purchase_enabled'])) {{ $__t('on') }} @else {{ $__t('off') }} @endif</span></button>
<input id="scan-mode" <input id="scan-mode"
type="checkbox" type="checkbox"
class="d-none user-setting-control" class="d-none user-setting-control"