Make it also possible to consume the whole stock of a product from stock overview

This commit is contained in:
Bernd Bestel
2018-05-13 08:42:45 +02:00
parent 6e4cd22118
commit 9837f79f9c
3 changed files with 32 additions and 9 deletions

View File

@@ -12,22 +12,31 @@ $(document).on('click', '.product-consume-button', function(e)
var productId = $(e.currentTarget).attr('data-product-id');
var productName = $(e.currentTarget).attr('data-product-name');
var productQuName = $(e.currentTarget).attr('data-product-qu-name');
var consumeAmount = $(e.currentTarget).attr('data-consume-amount');
Grocy.Api.Get('stock/consume-product/' + productId + '/1',
Grocy.Api.Get('stock/consume-product/' + productId + '/' + consumeAmount,
function(result)
{
var oldAmount = parseInt($('#product-' + productId + '-amount').text());
var newAmount = oldAmount - 1;
var newAmount = oldAmount - consumeAmount;
if (newAmount === 0)
{
$('#product-' + productId + '-row').remove();
$('#product-' + productId + '-row').fadeOut(500, function()
{
$(this).remove();
});
}
else
{
$('#product-' + productId + '-amount').text(newAmount);
$('#product-' + productId + '-amount').parent().effect('highlight', { }, 500);
$('#product-' + productId + '-amount').fadeOut(500, function()
{
$(this).text(newAmount).fadeIn(500);
});
$('#product-' + productId + '-consume-all-button').attr('data-consume-amount', newAmount);
}
toastr.success(L('Removed #1 #2 of #3 from stock', 1, productQuName, productName));
toastr.success(L('Removed #1 #2 of #3 from stock', consumeAmount, productQuName, productName));
},
function(xhr)
{