mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
This commit is contained in:
parent
df39f94fca
commit
daa0a59c5f
@ -151,6 +151,8 @@ AS (
|
||||
AND c.path LIKE ('%/' || s.from_qu_id || '/' || s.to_qu_id || '/%')
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT DISTINCT
|
||||
-1 AS id, -- Dummy, LessQL needs an id column
|
||||
c.product_id,
|
||||
@ -167,4 +169,23 @@ JOIN quantity_units qu_from
|
||||
ON c.from_qu_id = qu_from.id
|
||||
JOIN quantity_units qu_to
|
||||
ON c.to_qu_id = qu_to.id
|
||||
ORDER BY product_id, from_qu_id, to_qu_id;
|
||||
|
||||
UNION
|
||||
|
||||
-- Also return a conversion from/to the products stock QU (with a factor of 1)
|
||||
SELECT
|
||||
-1 AS id, -- Dummy, LessQL needs an id column
|
||||
p.id AS product_id,
|
||||
p.qu_id_stock AS from_qu_id,
|
||||
qu.name AS from_qu_name,
|
||||
qu.name_plural AS from_qu_name_plural,
|
||||
p.qu_id_stock AS to_qu_id,
|
||||
qu.name AS to_qu_name,
|
||||
qu.name_plural AS to_qu_name_plural,
|
||||
1.0 AS factor,
|
||||
'/' || p.qu_id_stock AS source
|
||||
FROM products p
|
||||
JOIN quantity_units qu
|
||||
ON p.qu_id_stock = qu.id
|
||||
) x
|
||||
ORDER BY x.product_id, x.from_qu_id, x.to_qu_id;
|
||||
|
@ -14,12 +14,10 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI
|
||||
conversionsForProduct.forEach(conversion =>
|
||||
{
|
||||
var factor = parseFloat(conversion.factor);
|
||||
if (conversion.to_qu_id == destinationQuId)
|
||||
{
|
||||
factor = 1;
|
||||
}
|
||||
|
||||
if (!$('#qu_id option[value="' + conversion.to_qu_id + '"]').length) // Don't add the destination QU multiple times
|
||||
// Only conversions related to the destination QU are needed
|
||||
// + only add one conversion per to_qu_id (multiple ones can be a result of contradictory definitions = user input bullshit)
|
||||
if (conversion.from_qu_id == destinationQuId && !$('#qu_id option[value="' + conversion.to_qu_id + '"]').length)
|
||||
{
|
||||
$("#qu_id").append('<option value="' + conversion.to_qu_id + '" data-qu-factor="' + factor + '" data-qu-name-plural="' + conversion.to_qu_name_plural + '">' + conversion.to_qu_name + '</option>');
|
||||
}
|
||||
@ -33,7 +31,7 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI
|
||||
|
||||
if (!Grocy.Components.ProductAmountPicker.InitialValueSet)
|
||||
{
|
||||
var convertedAmount = $("#display_amount").val() * $("#qu_id option:selected").attr("data-qu-factor");
|
||||
var convertedAmount = ($("#display_amount").val() * $("#qu_id option:selected").attr("data-qu-factor")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts });
|
||||
$("#display_amount").val(convertedAmount);
|
||||
|
||||
Grocy.Components.ProductAmountPicker.InitialValueSet = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user