Fixed JS / display errors on refreshing a row on /stockentries

This commit is contained in:
Bernd Bestel 2022-04-18 18:42:40 +02:00
parent 44c6865ba1
commit 900a49a36a
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

View File

@ -249,6 +249,11 @@ function RefreshStockEntryRow(stockRowId)
Grocy.Api.Get("stock/products/" + result.product_id,
function(productDetails)
{
if (result.price == null || result.price.isEmpty())
{
result.price = 0;
}
$('#stock-' + stockRowId + '-price').text(__t("%1$s per %2$s", (Number.parseFloat(result.price) * Number.parseFloat(productDetails.product.qu_factor_purchase_to_stock)).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), productDetails.default_quantity_unit_purchase.name));
$('#stock-' + stockRowId + '-price').attr("data-original-title", __t("%1$s per %2$s", Number.parseFloat(result.price).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), productDetails.quantity_unit_stock.name));
},
@ -262,20 +267,27 @@ function RefreshStockEntryRow(stockRowId)
$('#stock-' + stockRowId + '-purchased-date').text(result.purchased_date);
$('#stock-' + stockRowId + '-purchased-date-timeago').attr('datetime', result.purchased_date + ' 23:59:59');
var shoppingLocationName = "";
Grocy.Api.Get("objects/shopping_locations/" + result.shopping_location_id,
function(shoppingLocationResult)
{
shoppingLocationName = shoppingLocationResult.name;
if (result.shopping_location_id != null && !result.shopping_location_id.isEmpty())
{
var shoppingLocationName = "";
Grocy.Api.Get("objects/shopping_locations/" + result.shopping_location_id,
function(shoppingLocationResult)
{
shoppingLocationName = shoppingLocationResult.name;
$('#stock-' + stockRowId + '-shopping-location').attr('data-shopping-location-id', result.location_id);
$('#stock-' + stockRowId + '-shopping-location').text(shoppingLocationName);
},
function(xhr)
{
console.error(xhr);
}
);
$('#stock-' + stockRowId + '-shopping-location').attr('data-shopping-location-id', result.location_id);
$('#stock-' + stockRowId + '-shopping-location').text(shoppingLocationName);
},
function(xhr)
{
console.error(xhr);
}
);
}
else
{
$('#stock-' + stockRowId + '-shopping-location').text("");
}
if (result.open == 1)
{