Added UI feedback on auto moving

This commit is contained in:
Bernd Bestel 2022-04-18 18:23:17 +02:00
parent cb5b739886
commit 152905bf49
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
6 changed files with 46 additions and 5 deletions

View File

@ -4797,6 +4797,9 @@
"has_childs": {
"type": "boolean",
"description": "True when the product is a parent product of others"
},
"default_location": {
"$ref": "#/components/schemas/Location"
}
},
"example": {
@ -4862,7 +4865,8 @@
"row_created_timestamp": "2019-05-02 20:12:25"
},
"average_shelf_life_days": -1,
"spoil_rate_percent": 0
"spoil_rate_percent": 0,
"default_consume_location": null
}
},
"ProductPriceHistory": {

View File

@ -2332,3 +2332,6 @@ msgstr ""
msgid "When enabled, on marking this product as opened, the corresponding amount will be moved to the default consume location"
msgstr ""
msgid "Moved to %1$s"
msgstr ""

View File

@ -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);

View File

@ -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)
{

View File

@ -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);
},

View File

@ -734,6 +734,12 @@ class StockService extends BaseService
}
$spoilRate = ($consumeCountSpoiled * 100.0) / $consumeCount;
$defaultConsumeLocation = null;
if (!empty($product->default_consume_location_id))
{
$defaultConsumeLocation = $this->getDatabase()->locations($product->default_consume_location_id);
}
return [
'product' => $product,
'product_barcodes' => $productBarcodes,
@ -758,6 +764,7 @@ class StockService extends BaseService
'spoil_rate_percent' => $spoilRate,
'is_aggregated_amount' => $stockCurrentRow->is_aggregated_amount,
'has_childs' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0,
'default_consume_location' => $defaultConsumeLocation
];
}