From 33a6a282089ff067b6a26c46547407d3b077f97f Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 9 Nov 2020 22:15:25 +0100 Subject: [PATCH] Also use the productamountpicker on the shopping list item page (refernces #1015) --- changelog/60_UNRELEASED_2020-xx-xx.md | 2 +- controllers/StockController.php | 12 +++++++----- localization/strings.pot | 2 +- public/viewjs/components/productamountpicker.js | 2 +- public/viewjs/consume.js | 2 +- public/viewjs/inventory.js | 2 +- public/viewjs/shoppinglistitemform.js | 13 ++++++++----- public/viewjs/transfer.js | 2 +- views/components/productamountpicker.blade.php | 1 + views/shoppinglistitemform.blade.php | 13 +++++++------ 10 files changed, 29 insertions(+), 22 deletions(-) diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 7b3de9e4..682c2be2 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -25,7 +25,7 @@ - (Thanks @fipwmaqzufheoxq92ebc for the initial work on this) ### Stock improvements/fixes -- On the purchase/consume/transfer/inventory page any product related quantity unit can now be used +- On the purchase/consume/transfer/inventory/shopping list item page (so everywhere) any product related quantity unit can now be used - When creating a quantity unit conversion it's now possible to automatically create the inverse conversion (thanks @kriddles) - 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) diff --git a/controllers/StockController.php b/controllers/StockController.php index 4e7ded19..e68e37d2 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -30,9 +30,7 @@ class StockController extends BaseController 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'), 'barcodes' => $productBarcodes, 'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'), - 'locations' => $this->getDatabase()->locations()->orderBy('name'), - 'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'), - 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() + 'locations' => $this->getDatabase()->locations()->orderBy('name') ]); } @@ -347,7 +345,9 @@ class StockController extends BaseController return $this->renderPage($response, 'shoppinglistitemform', [ 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'), 'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'), - 'mode' => 'create' + 'mode' => 'create', + 'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'), + 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() ]); } else @@ -356,7 +356,9 @@ class StockController extends BaseController 'listItem' => $this->getDatabase()->shopping_list($args['itemId']), 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'), 'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'), - 'mode' => 'edit' + 'mode' => 'edit', + 'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'), + 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() ]); } } diff --git a/localization/strings.pot b/localization/strings.pot index b43b4729..17ba3c7d 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1374,7 +1374,7 @@ msgstr "" msgid "Override for product" msgstr "" -msgid "This equals %1$s %2$s in stock" +msgid "This equals %1$s %2$s" msgstr "" msgid "Edit QU conversion" diff --git a/public/viewjs/components/productamountpicker.js b/public/viewjs/components/productamountpicker.js index 14751f80..44b00a15 100644 --- a/public/viewjs/components/productamountpicker.js +++ b/public/viewjs/components/productamountpicker.js @@ -87,7 +87,7 @@ $(".input-group-productamountpicker").on("change", function() else { $("#qu-conversion-info").removeClass("d-none"); - $("#qu-conversion-info").text(__t("This equals %1$s %2$s in stock", destinationAmount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), destinationQuName)); + $("#qu-conversion-info").text(__t("This equals %1$s %2$s", destinationAmount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), destinationQuName)); } $("#amount").val(destinationAmount.toFixed(4).replace(/0*$/g, '')); diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 8cd429d5..56f926de 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -272,7 +272,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) function(productDetails) { Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); - Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_purchase.id); + Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id); $("#location_id").find("option").remove().end().append(""); Grocy.Api.Get("stock/products/" + productId + '/locations', diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index dd99ebe8..807e88b8 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -133,7 +133,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) function(productDetails) { Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); - Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_purchase.id); + Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id); $('#display_amount').attr('data-not-equal', productDetails.stock_amount); diff --git a/public/viewjs/shoppinglistitemform.js b/public/viewjs/shoppinglistitemform.js index d7a953d4..ee4099e2 100644 --- a/public/viewjs/shoppinglistitemform.js +++ b/public/viewjs/shoppinglistitemform.js @@ -3,6 +3,8 @@ e.preventDefault(); var jsonData = $('#shoppinglist-form').serializeJSON(); + delete jsonData.display_amount; + delete jsonData.qu_id; Grocy.FrontendHelpers.BeginUiBusy("shoppinglist-form"); if (GetUriParam("updateexistingproduct") !== undefined) @@ -118,9 +120,10 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Api.Get('stock/products/' + productId, function(productDetails) { - $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); + Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_purchase.id); + Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_purchase.id); - $('#amount').focus(); + $('#display_amount').focus(); Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); }, function(xhr) @@ -140,7 +143,7 @@ if (Grocy.EditMode === "edit") Grocy.Components.ProductPicker.GetPicker().trigger('change'); } -$('#amount').on('focus', function(e) +$('#display_amount').on('focus', function(e) { $(this).select(); }); @@ -174,8 +177,8 @@ if (GetUriParam("list") !== undefined) if (GetUriParam("amount") !== undefined) { - $("#amount").val(parseFloat(GetUriParam("amount")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts })); + $("#display_amount").val(parseFloat(GetUriParam("amount")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts })); Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); } -$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1")); +$("#display_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1")); diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index 2d6effbb..e80b0596 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -139,7 +139,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) function(productDetails) { Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); - Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_purchase.id); + Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id); if (productDetails.product.enable_tare_weight_handling == 1) { diff --git a/views/components/productamountpicker.blade.php b/views/components/productamountpicker.blade.php index d9c50878..0a3bc702 100644 --- a/views/components/productamountpicker.blade.php +++ b/views/components/productamountpicker.blade.php @@ -6,6 +6,7 @@ @php if(empty($additionalHtmlContextHelp)) { $additionalHtmlContextHelp = ''; } @endphp @php if(empty($additionalHtmlElements)) { $additionalHtmlElements = ''; } @endphp @php if(empty($label)) { $label = 'Amount'; } @endphp +@php if(empty($initialQuId)) { $initialQuId = '-1'; } @endphp
diff --git a/views/shoppinglistitemform.blade.php b/views/shoppinglistitemform.blade.php index 9d1ee6dc..9d8d95ad 100644 --- a/views/shoppinglistitemform.blade.php +++ b/views/shoppinglistitemform.blade.php @@ -9,6 +9,11 @@ @section('viewJsName', 'shoppinglistitemform') @section('content') + +

@yield('title')

@@ -62,13 +67,9 @@ ))
@php if($mode == 'edit') { $value = $listItem->amount; } else { $value = 1; } @endphp - @include('components.numberpicker', array( - 'id' => 'amount', - 'label' => 'Amount', - 'hintId' => 'amount_qu_unit', - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', - 'decimals' => $userSettings['stock_decimal_places_amounts'], + @include('components.productamountpicker', array( 'value' => $value, + 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', 'invalidFeedback' => $__t('The amount cannot be lower than %s', '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1') ))