Related the price on /inventory to the selected QU instead of QU stock (closes #1346)

This commit is contained in:
Bernd Bestel 2022-04-06 21:27:47 +02:00
parent e91fa02974
commit cab34df2d6
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 51 additions and 8 deletions

View File

@ -44,6 +44,7 @@
- The location content sheet can now optionally list also out of stock products (at the products default location, new checkbox "Show only in-stock products " at the top of the page, defaults to enabled)
- Added a location filter to the stock entries page
- Added the product grocycode as a (hidden by default) column to the products list (master data)
- The price entered on the inventory page is now related to the selected quantity unit (like on the purchase page, was always related to the products stock QU before)
- Fixed that consuming via the consume page was not possible when `FEATURE_FLAG_STOCK_LOCATION_TRACKING` was disabled
### Shopping list

View File

@ -1,4 +1,6 @@
$('#save-inventory-button').on('click', function(e)
var CurrentProductDetails;
$('#save-inventory-button').on('click', function(e)
{
e.preventDefault();
@ -21,7 +23,7 @@
var price = "";
if (!jsonForm.price.toString().isEmpty())
{
price = parseFloat(jsonForm.price).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
price = parseFloat(jsonForm.price * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
}
var jsonData = {};
@ -150,6 +152,7 @@
$(".input-group-productamountpicker").trigger("change");
$('#price').val('');
$('#note').val('');
$('#price-hint').text("");
Grocy.Components.DateTimePicker.Clear();
Grocy.Components.ProductPicker.SetValue('');
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
@ -202,6 +205,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
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.quantity_unit_stock.id);
@ -219,7 +224,15 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
$("#tare-weight-handling-info").addClass("d-none");
}
$('#price').val(parseFloat(productDetails.last_price));
if (productDetails.last_price != null && !productDetails.last_price.isEmpty())
{
$('#price').val(parseFloat(productDetails.last_price / $("#qu_id option:selected").attr("data-qu-factor")));
}
else
{
$('#price').val("");
}
RefreshLocaleNumberInput();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
@ -293,6 +306,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
$(".input-group-productamountpicker").trigger("change");
$('#display_amount').focus();
$('#display_amount').trigger('keyup');
refreshPriceHint();
},
function(xhr)
{
@ -302,6 +316,31 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
}
});
function refreshPriceHint()
{
if ($('#amount').val() == 0 || $('#price').val() == 0)
{
$('#price-hint').text("");
return;
}
if ($("#qu_id").attr("data-destination-qu-name") != $("#qu_id option:selected").text())
{
var amount = $('#display_amount').val();
if (BoolVal(CurrentProductDetails.product.enable_tare_weight_handling))
{
amount -= parseFloat(CurrentProductDetails.product.tare_weight);
}
var price = parseFloat($('#price').val() * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
$('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));
}
else
{
$('#price-hint').text("");
}
};
$('#display_amount').val('');
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('inventory-form');
@ -371,6 +410,11 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#price').on('focus', function(e)
{
$(this).select();
});
$('#display_amount').on('keyup', function(e)
{
var productId = Grocy.Components.ProductPicker.GetValue();
@ -426,6 +470,7 @@ $('#display_amount').on('keyup', function(e)
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
}
refreshPriceHint();
Grocy.FrontendHelpers.ValidateForm('inventory-form');
},
function(xhr)

View File

@ -85,11 +85,8 @@
'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_prices']),
'decimals' => $userSettings['stock_decimal_places_prices'],
'value' => '',
'hint' => $__t('Per stock quantity unit', GROCY_CURRENCY),
'additionalHtmlContextHelp' => '<i class="fa-solid fa-question-circle text-muted"
data-toggle="tooltip"
data-trigger="hover click"
title="' . $__t('This will apply to added products') . '"></i>',
'contextInfoId' => 'price-hint',
'hint' => $__t('This will apply to added products'),
'isRequired' => false,
'additionalCssClasses' => 'locale-number-input locale-number-currency'
))