mirror of
https://github.com/grocy/grocy.git
synced 2025-10-12 16:44:55 +00:00
Add support for "Move on Open" (#1863)
* Add functionality to move a product when it is opened * Update the API to support this (and some other new fields) * Remove console, update move on open when either the default or the consume location change * Fix conflict from fridge * Ignore .DS_STORE from macOS * Fix the migration conflict * Fix the default location not appending properly * Revert changes no longer needed * Fix the checkbox disable logic, and call the function on page load * Simplify the transfer to use the existing function (which also adds logs) * Only move it if it's moving * Code formatting / naming * Clarify help text (it's not always about one unit, but about the corresponding amount opened) * Handle splitted stock entries + optimized/unified product property checks * Added UI feedback on auto moving Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
@@ -189,6 +189,11 @@ $('#save-mark-as-open-button').on('click', function(e)
|
||||
Grocy.FrontendHelpers.EndUiBusy("consume-form");
|
||||
toastr.success(__t('Marked %1$s of %2$s as opened', parseFloat(jsonForm.amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural, true), productDetails.product.name) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockTransaction(\'' + result[0].transaction_id + '\')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
|
||||
if (productDetails.product.move_on_open == 1)
|
||||
{
|
||||
toastr.info('<span>' + __t("Moved to %1$s", productDetails.default_consume_location.name) + "</span> <i class='fa-solid fa-exchange-alt'></i>");
|
||||
}
|
||||
|
||||
if (BoolVal(Grocy.UserSettings.stock_default_consume_amount_use_quick_consume_amount))
|
||||
{
|
||||
$('#display_amount').val(productDetails.product.quick_consume_amount);
|
||||
|
@@ -239,8 +239,30 @@ $('#product-form input').keyup(function(event)
|
||||
$('#location_id').change(function(event)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('product-form');
|
||||
UpdateMoveOnOpen();
|
||||
});
|
||||
|
||||
$('#default_consume_location_id').change(function(event)
|
||||
{
|
||||
UpdateMoveOnOpen();
|
||||
});
|
||||
|
||||
function UpdateMoveOnOpen()
|
||||
{
|
||||
var defaultLocation = $("#location_id :selected").val();
|
||||
var consumeLocationLocation = $("#default_consume_location_id :selected").val();
|
||||
|
||||
if (!consumeLocationLocation || defaultLocation === consumeLocationLocation)
|
||||
{
|
||||
document.getElementById("move_on_open").checked = false;
|
||||
$("#move_on_open").attr("disabled", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#move_on_open").attr("disabled", false);
|
||||
}
|
||||
}
|
||||
|
||||
$('#product-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) // Enter
|
||||
@@ -556,6 +578,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
}
|
||||
});
|
||||
|
||||
UpdateMoveOnOpen();
|
||||
Grocy.FrontendHelpers.ValidateForm("product-form");
|
||||
Grocy.Components.ProductPicker.GetPicker().trigger("change");
|
||||
|
||||
|
@@ -126,10 +126,26 @@ $(document).on('click', '.product-open-button', function(e)
|
||||
Grocy.Api.Post('stock/products/' + productId + '/open', { 'amount': 1, 'stock_entry_id': specificStockEntryId },
|
||||
function(bookingResponse)
|
||||
{
|
||||
button.addClass("disabled");
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
toastr.success(__t('Marked %1$s of %2$s as opened', 1 + " " + productQuName, productName) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(' + bookingResponse[0].id + ',' + stockRowId + ')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
RefreshStockEntryRow(stockRowId);
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(result)
|
||||
{
|
||||
button.addClass("disabled");
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
toastr.success(__t('Marked %1$s of %2$s as opened', 1 + " " + productQuName, productName) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(' + bookingResponse[0].id + ',' + stockRowId + ')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
|
||||
if (result.product.move_on_open == 1)
|
||||
{
|
||||
toastr.info('<span>' + __t("Moved to %1$s", result.default_consume_location.name) + "</span> <i class='fa-solid fa-exchange-alt'></i>");
|
||||
}
|
||||
|
||||
RefreshStockEntryRow(stockRowId);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
@@ -208,6 +208,12 @@ $(document).on('click', '.product-open-button', function(e)
|
||||
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
toastr.success(__t('Marked %1$s of %2$s as opened', parseFloat(amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + productQuName, productName) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
|
||||
if (result.product.move_on_open == 1)
|
||||
{
|
||||
toastr.info('<span>' + __t("Moved to %1$s", result.default_consume_location.name) + "</span> <i class='fa-solid fa-exchange-alt'></i>");
|
||||
}
|
||||
|
||||
RefreshStatistics();
|
||||
RefreshProductRow(productId);
|
||||
},
|
||||
|
Reference in New Issue
Block a user