mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Test/review/rework (and hopefully finalized) new price handling
This commit is contained in:
@@ -486,6 +486,7 @@ canvas.drawingBuffer {
|
||||
.user-filter-message {
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
line-height: 0.5;
|
||||
}
|
||||
|
||||
.related-links .btn {
|
||||
|
@@ -11,7 +11,7 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI
|
||||
$("#qu_id").attr("data-destination-qu-name", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name);
|
||||
conversionsForProduct.forEach(conversion =>
|
||||
{
|
||||
var factor = conversion.factor;
|
||||
var factor = parseFloat(conversion.factor);
|
||||
if (conversion.to_qu_id == destinationQuId)
|
||||
{
|
||||
factor = 1;
|
||||
@@ -39,6 +39,15 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI
|
||||
$("#qu_id").val($("#qu_id option:first").val());
|
||||
}
|
||||
|
||||
if ($('#qu_id option').length == 1)
|
||||
{
|
||||
$("#qu_id").attr("disabled", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#qu_id").removeAttr("disabled");
|
||||
}
|
||||
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
}
|
||||
|
||||
|
@@ -6,23 +6,12 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
function(productDetails)
|
||||
{
|
||||
var stockAmount = productDetails.stock_amount || '0';
|
||||
var stockFactorPurchaseAmount = productDetails.stock_factor_purchase_amount || '0';
|
||||
var stockValue = productDetails.stock_value || '0';
|
||||
var stockAmountOpened = productDetails.stock_amount_opened || '0';
|
||||
$('#productcard-product-name').text(productDetails.product.name);
|
||||
$('#productcard-product-description').html(productDetails.product.description);
|
||||
$('#productcard-product-stock-amount').text(stockAmount);
|
||||
$('#productcard-product-stock-qu-name').text(__n(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural));
|
||||
if (productDetails.last_qu_factor_purchase_to_stock > 1)
|
||||
{
|
||||
$('#productcard-product-stock-factor-purchase-amount').text('(' + stockFactorPurchaseAmount);
|
||||
$('#productcard-product-stock-factor-purchase-qu-name').text(__n(stockFactorPurchaseAmount, productDetails.quantity_unit_purchase.name, productDetails.quantity_unit_purchase.name_plural) + ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-stock-factor-purchase-amount').text('');
|
||||
$('#productcard-product-stock-factor-purchase-qu-name').text('');
|
||||
}
|
||||
$('#productcard-product-stock-value').text(stockValue + ' ' + Grocy.Currency);
|
||||
$('#productcard-product-last-purchased').text((productDetails.last_purchased || '2999-12-31').substring(0, 10));
|
||||
$('#productcard-product-last-purchased-timeago').attr("datetime", productDetails.last_purchased || '2999-12-31');
|
||||
@@ -95,14 +84,7 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
|
||||
if (productDetails.last_price !== null)
|
||||
{
|
||||
if (productDetails.last_qu_factor_purchase_to_stock > 1)
|
||||
{
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price * productDetails.last_qu_factor_purchase_to_stock).toLocaleString() + ' ' + Grocy.Currency + ' per 1 ' + productDetails.quantity_unit_purchase.name + ' of ' + productDetails.last_qu_factor_purchase_to_stock + ' ' + productDetails.quantity_unit_stock.name_plural);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per ' + productDetails.quantity_unit_purchase.name);
|
||||
}
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per ' + productDetails.quantity_unit_stock.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -48,7 +48,6 @@
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
|
@@ -45,7 +45,6 @@
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
|
||||
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
|
@@ -79,5 +79,5 @@ $('#location-form input').keydown(function(event)
|
||||
});
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
||||
$('#name').focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('location-form');
|
||||
$('#name').focus();
|
||||
|
@@ -180,11 +180,6 @@ var calendar = $("#calendar").fullCalendar({
|
||||
productDetails.last_price = 0;
|
||||
}
|
||||
|
||||
if (productDetails.last_qu_factor_purchase_to_stock === null)
|
||||
{
|
||||
productDetails.last_qu_factor_purchase_to_stock = 1;
|
||||
}
|
||||
|
||||
element.attr("data-product-details", event.productDetails);
|
||||
|
||||
var productOrderMissingButtonDisabledClasses = "disabled";
|
||||
@@ -210,7 +205,7 @@ var calendar = $("#calendar").fullCalendar({
|
||||
var costsAndCaloriesPerServing = ""
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||
{
|
||||
costsAndCaloriesPerServing = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + productDetails.last_price / productDetails.last_qu_factor_purchase_to_stock * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories * mealPlanEntry.product_amount + '</span> kcal ' + '<h5>';
|
||||
costsAndCaloriesPerServing = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + productDetails.last_price * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories * mealPlanEntry.product_amount + '</span> kcal ' + '<h5>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -3,6 +3,9 @@
|
||||
e.preventDefault();
|
||||
|
||||
var jsonData = $('#barcode-form').serializeJSON();
|
||||
jsonData.amount = jsonData.display_amount;
|
||||
delete jsonData.display_amount;
|
||||
|
||||
Grocy.FrontendHelpers.BeginUiBusy("barcode-form");
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
@@ -36,12 +39,17 @@
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
|
||||
});
|
||||
|
||||
$('#barcode').on('change', function(e)
|
||||
$('#barcode').on('keyup', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
});
|
||||
|
||||
$('#qu_factor_purchase_to_stock').on('change', function(e)
|
||||
$('#qu_id').on('change', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
});
|
||||
|
||||
$('#display_amount').on('keyup', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
});
|
||||
@@ -62,4 +70,13 @@ $('#barcode-form input').keydown(function(event)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.Components.ProductAmountPicker.Reload(Grocy.EditObjectProduct.id, Grocy.EditObjectProduct.qu_id_purchase);
|
||||
if (Grocy.EditMode == "edit")
|
||||
{
|
||||
$("#display_amount").val(Grocy.EditObject.amount);
|
||||
Grocy.Components.ProductAmountPicker.SetQuantityUnit(Grocy.EditObject.qu_id);
|
||||
}
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
$('#barcode').focus();
|
@@ -8,6 +8,12 @@
|
||||
Grocy.Api.UploadFile($("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name,
|
||||
(result) =>
|
||||
{
|
||||
if (Grocy.ProductEditFormRedirectUri == "reload")
|
||||
{
|
||||
window.location.reload();
|
||||
return
|
||||
}
|
||||
|
||||
var returnTo = GetUriParam('returnto');
|
||||
if (GetUriParam("closeAfterCreation") !== undefined)
|
||||
{
|
||||
@@ -32,6 +38,12 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Grocy.ProductEditFormRedirectUri == "reload")
|
||||
{
|
||||
window.location.reload();
|
||||
return
|
||||
}
|
||||
|
||||
var returnTo = GetUriParam('returnto');
|
||||
if (GetUriParam("closeAfterCreation") !== undefined)
|
||||
{
|
||||
@@ -145,9 +157,6 @@ $('.input-group-qu').on('change', function(e)
|
||||
$('#qu-conversion-info').addClass('d-none');
|
||||
}
|
||||
|
||||
$("#qu-conversion-headline-info").text(__t('1 %s is the same as...', $("#qu_id_stock option:selected").text()));
|
||||
quConversionsTable.column(4).search("from_qu_id xx" + $("#qu_id_stock").val().toString() + "xx").draw();
|
||||
|
||||
$("#tare_weight_qu_info").text($("#qu_id_stock option:selected").text());
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm('product-form');
|
||||
@@ -301,14 +310,14 @@ if (Grocy.EditMode === 'create')
|
||||
|
||||
var quConversionsTable = $('#qu-conversions-table').DataTable({
|
||||
'order': [[1, 'asc']],
|
||||
"orderFixed": [[3, 'asc']],
|
||||
"orderFixed": [[4, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 },
|
||||
{ 'searchable': false, "targets": 0 },
|
||||
{ 'visible': false, 'targets': 3 }
|
||||
{ 'visible': false, 'targets': 4 }
|
||||
],
|
||||
'rowGroup': {
|
||||
dataSrc: 3
|
||||
dataSrc: 4
|
||||
}
|
||||
});
|
||||
$('#qu-conversions-table tbody').removeClass("d-none");
|
||||
|
@@ -3,7 +3,6 @@
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#purchase-form').serializeJSON();
|
||||
jsonForm.qu_factor_purchase_to_stock = $("#qu_id option:selected").attr("data-qu-factor");
|
||||
|
||||
Grocy.FrontendHelpers.BeginUiBusy("purchase-form");
|
||||
|
||||
@@ -16,14 +15,14 @@
|
||||
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||
{
|
||||
jsonData.price = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// price is saved as 1 QU to stock
|
||||
var price = parseFloat(jsonForm.price / jsonForm.qu_factor_purchase_to_stock).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
var price = parseFloat(jsonForm.price * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
|
||||
if ($("input[name='price-type']:checked").val() == "total-price")
|
||||
{
|
||||
price = parseFloat(price / jsonForm.amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
price = parseFloat(price / jsonForm.display_amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
}
|
||||
jsonData.price = price;
|
||||
}
|
||||
@@ -50,7 +49,6 @@
|
||||
{
|
||||
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
||||
}
|
||||
jsonData.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
|
||||
function(result)
|
||||
@@ -66,7 +64,6 @@
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
|
||||
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
@@ -122,6 +119,12 @@
|
||||
}
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
Grocy.Components.ProductCard.Refresh(jsonForm.product_id);
|
||||
|
||||
$('#price-hint').text("");
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
|
||||
priceTypeUnitPriceLabel.text(__t("Unit price"));
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||
}
|
||||
},
|
||||
@@ -155,67 +158,17 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
if (document.getElementById("product_id").getAttribute("barcode") != "null")
|
||||
{
|
||||
Grocy.Api.Get('productbarcodedetails/' + document.getElementById("product_id").getAttribute("barcode"),
|
||||
function(resultBarcode)
|
||||
{
|
||||
if (resultBarcode != null)
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", resultBarcode.qu_factor_purchase_to_stock);
|
||||
$('#product_id').attr("barcode-shopping-location-id", resultBarcode.shopping_location_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
|
||||
$('#product_id').attr("barcode-shopping-location-id", "null");
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
|
||||
$('#product_id').attr("barcode-shopping-location-id", "null");
|
||||
}
|
||||
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
|
||||
Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_purchase.id);
|
||||
|
||||
var qu_factor_purchase_to_stock = null;
|
||||
var barcode_shopping_location_id = null;
|
||||
|
||||
if (document.getElementById("product_id").getAttribute("barcode") != "null" && document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock") != "null")
|
||||
{
|
||||
qu_factor_purchase_to_stock = document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock");
|
||||
barcode_shopping_location_id = document.getElementById("product_id").getAttribute("barcode-shopping-location-id");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (productDetails.last_qu_factor_purchase_to_stock != null)
|
||||
{
|
||||
qu_factor_purchase_to_stock = productDetails.last_qu_factor_purchase_to_stock;
|
||||
}
|
||||
else
|
||||
{
|
||||
qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
}
|
||||
}
|
||||
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||
{
|
||||
if (barcode_shopping_location_id != null)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(barcode_shopping_location_id);
|
||||
}
|
||||
else if (productDetails.last_shopping_location_id != null)
|
||||
if (productDetails.last_shopping_location_id != null)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id);
|
||||
}
|
||||
@@ -230,11 +183,11 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||
}
|
||||
|
||||
$('#price').val(parseFloat(productDetails.last_price * qu_factor_purchase_to_stock).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
$('#price').val(parseFloat(productDetails.last_price / $("#qu_id option:selected").attr("data-qu-factor")).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
|
||||
priceTypeUnitPriceLabel.text(productDetails.quantity_unit_purchase.name + " price");
|
||||
priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
|
||||
|
||||
refreshPriceHint();
|
||||
|
||||
@@ -253,7 +206,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
|
||||
if (productDetails.product.enable_tare_weight_handling == 1)
|
||||
{
|
||||
var minAmount = parseFloat(productDetails.product.tare_weight) / qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
|
||||
var minAmount = parseFloat(productDetails.product.tare_weight) / $("#qu_id option:selected").attr("data-qu-factor") + parseFloat(productDetails.stock_amount);
|
||||
$("#display_amount").attr("min", minAmount);
|
||||
$("#display_amount").attr("step", "." + "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', minAmount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts })));
|
||||
@@ -304,6 +257,40 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
Grocy.UISound.Error();
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById("product_id").getAttribute("barcode") != "null")
|
||||
{
|
||||
Grocy.Api.Get('objects/product_barcodes/search/?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
|
||||
function(barcodeResult)
|
||||
{
|
||||
if (barcodeResult != null)
|
||||
{
|
||||
var barcode = barcodeResult[0];
|
||||
|
||||
if (barcode.amount != null)
|
||||
{
|
||||
$("#display_amount").val(barcode.amount);
|
||||
}
|
||||
|
||||
if (barcode.qu_id != null)
|
||||
{
|
||||
Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id);
|
||||
}
|
||||
|
||||
if (barcode.shopping_location_id != null)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(barcode.shopping_location_id);
|
||||
}
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -409,12 +396,7 @@ if (GetUriParam("flow") === "shoppinglistitemtostock")
|
||||
|
||||
function refreshPriceHint()
|
||||
{
|
||||
if ($('#amount').val() == 0)
|
||||
{
|
||||
$('#price-hint').text("");
|
||||
return;
|
||||
}
|
||||
if ($('#price').val() == 0)
|
||||
if ($('#amount').val() == 0 || $('#price').val() == 0)
|
||||
{
|
||||
$('#price-hint').text("");
|
||||
return;
|
||||
@@ -422,29 +404,14 @@ function refreshPriceHint()
|
||||
|
||||
if ($("input[name='price-type']:checked").val() == "total-price")
|
||||
{
|
||||
var price = $('#price').val() / $("#qu_id option:selected").attr("data-qu-factor") / $('#amount').val();
|
||||
var quprice = $('#price').val() / $('#amount').val();
|
||||
var price = parseFloat($('#price').val() * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
price = parseFloat(price / $('#display_amount').val()).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
|
||||
|
||||
if ($("#qu_id option:selected").attr("data-qu-factor") > 1)
|
||||
{
|
||||
$('#price-hint').text(__t('means %1$s per %2$s and %3$s per %4$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name"), quprice.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-purchase-name")));
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));
|
||||
}
|
||||
$('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($("#qu_id option:selected").attr("data-qu-factor") > 1)
|
||||
{
|
||||
var price = $('#price').val() / $("#qu_id option:selected").attr("data-qu-factor");
|
||||
$('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#price-hint').text("");
|
||||
}
|
||||
$('#price-hint').text("");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -520,3 +487,10 @@ $("#scan-mode-button").on("click", function(e)
|
||||
$("#scan-mode-status").text(__t("off"));
|
||||
}
|
||||
});
|
||||
|
||||
$('#qu_id').on('change', function(e)
|
||||
{
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
|
||||
priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
|
||||
});
|
||||
|
@@ -174,12 +174,12 @@ $('.input-group-qu').on('change', function(e)
|
||||
|
||||
if (fromQuId && toQuId)
|
||||
{
|
||||
$('#qu-conversion-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $("#from_qu_id option:selected").text(), (1 * factor).toString(), __n((1 * factor).toString(), $("#to_qu_id option:selected").text(), $("#to_qu_id option:selected").data("plural-form"))));
|
||||
$('#qu-conversion-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $("#from_qu_id option:selected").text(), parseFloat((1 * factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 * factor).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), $("#to_qu_id option:selected").text(), $("#to_qu_id option:selected").data("plural-form"))));
|
||||
$('#qu-conversion-info').removeClass('d-none');
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
$('#qu-conversion-inverse-info').text('(' + __t('This means 1 %1$s is the same as %2$s %3$s', $("#to_qu_id option:selected").text(), (1 / factor).toString(), __n((1 / factor).toString(), $("#from_qu_id option:selected").text(), $("#from_qu_id option:selected").data("plural-form"))) + ')');
|
||||
$('#qu-conversion-inverse-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $("#to_qu_id option:selected").text(), parseFloat((1 / factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 / factor).toString(), $("#from_qu_id option:selected").text(), $("#from_qu_id option:selected").data("plural-form"))));
|
||||
$('#qu-conversion-inverse-info').removeClass('d-none');
|
||||
}
|
||||
}
|
||||
@@ -196,3 +196,8 @@ Grocy.Components.UserfieldsForm.Load();
|
||||
$('.input-group-qu').trigger('change');
|
||||
$('#from_qu_id').focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('quconversion-form');
|
||||
|
||||
if (GetUriParam("qu-unit") !== undefined)
|
||||
{
|
||||
$("#from_qu_id").attr("disabled", "");
|
||||
}
|
||||
|
@@ -177,7 +177,6 @@ function RefreshStockEntryRow(stockRowId)
|
||||
);
|
||||
|
||||
$('#stock-' + stockRowId + '-price').text(result.price);
|
||||
$('#stock-' + stockRowId + '-qu-factor-purchase-to-stock').text(result.qu_factor_purchase_to_stock);
|
||||
$('#stock-' + stockRowId + '-purchased-date').text(result.purchased_date);
|
||||
$('#stock-' + stockRowId + '-purchased-date-timeago').attr('datetime', result.purchased_date + ' 23:59:59');
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
jsonData.location_id = 1;
|
||||
}
|
||||
jsonData.price = price;
|
||||
jsonData.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
|
||||
jsonData.open = $("#open").is(":checked");
|
||||
|
||||
|
@@ -291,7 +291,6 @@ function RefreshProductRow(productId)
|
||||
$('#product-' + productId + '-qu-name').text(__n(result.stock_amount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural));
|
||||
$('#product-' + productId + '-amount').text(result.stock_amount);
|
||||
$('#product-' + productId + '-consume-all-button').attr('data-consume-amount', result.stock_amount);
|
||||
$('#product-' + productId + '-factor-purchase-amount').text(__t('( %s', result.stock_factor_purchase_amount));
|
||||
$('#product-' + productId + '-value').text(result.stock_value);
|
||||
$('#product-' + productId + '-next-best-before-date').text(result.next_best_before_date);
|
||||
$('#product-' + productId + '-next-best-before-date-timeago').attr('datetime', result.next_best_before_date);
|
||||
|
@@ -33,7 +33,6 @@
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
|
Reference in New Issue
Block a user