From e59a35c6d11d11f32b40c40fcca27cdde0f0f32b Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Fri, 27 Sep 2019 08:30:08 +0200 Subject: [PATCH] Also refresh the parent product on sub product actions on the stock overview page (closes #394) --- changelog/53_UNRELEASED_2019-xx-xx.md | 1 + public/viewjs/stockoverview.js | 28 +++++++++++++++++++++++++++ services/DemoDataGeneratorService.php | 4 ++-- views/stockoverview.blade.php | 4 ++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/changelog/53_UNRELEASED_2019-xx-xx.md b/changelog/53_UNRELEASED_2019-xx-xx.md index 66e8f2cd..84392855 100644 --- a/changelog/53_UNRELEASED_2019-xx-xx.md +++ b/changelog/53_UNRELEASED_2019-xx-xx.md @@ -2,6 +2,7 @@ - Fixed that barcode lookups now compare the whole barcode, not parts of it (e. g. when you have two products with the barcodes `$1` and `$10` and scan `$1` maybe the product of `$10` was found till now) - Fixed that the "X products are already expired" count on the stock overview page was wrong - Fixed that after product actions (consume/purchase/etc.) on the stock overview page the highlighting of the row was maybe wrong +- After product actions (consume/purchase/etc.) on the stock overview page on a sub product, now also the parent product (row) is refreshed - It's now possible to accumulate min. stock amounts on parent product level (new option per product, means the sub product will never be "missing" then, only the parent product) - When adding a product to the shopping list from the new context/more menu from the stock overview page and if the product is already on the shopping list, the amount of that entry will be updated acccordingly instead of adding a new (double) shopping list item diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index c5a53a65..d2616642 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -312,6 +312,12 @@ function RefreshProductRow(productId) Grocy.Api.Get('stock/products/' + productId, function(result) { + // Also refresh the parent product, if any + if (result.product.parent_product_id !== null && !result.product.parent_product_id.toString().isEmpty()) + { + RefreshProductRow(result.product.parent_product_id); + } + var productRow = $('#product-' + productId + '-row'); var expiringThreshold = moment().add($("#info-expiring-products").data("next-x-days"), "days"); var now = moment(); @@ -396,10 +402,32 @@ function RefreshProductRow(productId) $('#product-' + productId + '-opened-amount').text(""); } + if (parseInt(result.is_aggregated_amount) === 1) + { + $('#product-' + productId + '-amount-aggregated').fadeOut(500, function() + { + $(this).text(result.stock_amount_aggregated).fadeIn(500); + }); + + if (result.stock_amount_opened_aggregated > 0) + { + $('#product-' + productId + '-opened-amount-aggregated').parent().effect('highlight', {}, 500); + $('#product-' + productId + '-opened-amount-aggregated').fadeOut(500, function () + { + $(this).text(__t('%s opened', result.stock_amount_opened_aggregated)).fadeIn(500); + }); + } + else + { + $('#product-' + productId + '-opened-amount-aggregated').text(""); + } + } + // Needs to be delayed because of the animation above the date-text would be wrong if fired immediately... setTimeout(function() { RefreshContextualTimeago(); + RefreshLocaleNumberDisplay(); }, 600); }, function(xhr) diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 11b72273..76d217ac 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -68,7 +68,7 @@ class DemoDataGeneratorService extends BaseService DELETE FROM sqlite_sequence WHERE name = 'products'; --Just to keep IDs in order as mentioned here... INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$this->__t_sql('Cookies')}', 4, 3, 3, 1, 8, 1, 'cookies.jpg'); --1 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$this->__t_sql('Chocolate')}', 4, 3, 3, 1, 8, 1); --2 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, cumulate_min_stock_amount_of_sub_products) VALUES ('{$this->__t_sql('Chocolate')}', 4, 3, 3, 1, 8, 1, 1); --2 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$this->__t_sql('Gummy bears')}', 4, 3, 3, 1, 8, 1, 'gummybears.jpg'); --3 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$this->__t_sql('Crisps')}', 4, 3, 3, 1, 10, 1); --4 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Eggs')}', 2, 3, 2, 10, 5); --5 @@ -92,7 +92,7 @@ class DemoDataGeneratorService extends BaseService INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, calories) VALUES ('{$this->__t_sql('Milk')}', 2, 10, 10, 1, 6, 1); --23 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, parent_product_id) VALUES ('{$this->__t_sql('Milk Chocolate')}', 4, 3, 3, 1, 1, 2); --24 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, parent_product_id) VALUES ('{$this->__t_sql('Dark Chocolate')}', 4, 3, 3, 1, 1, 2); --25 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, parent_product_id, barcode) VALUES ('{$this->__t_sql('Waffle rolls')}', 4, 3, 3, 1, 1, 2, '22111289'); --26 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, barcode) VALUES ('{$this->__t_sql('Waffle rolls')}', 4, 3, 3, 1, 1, '22111289'); --26 UPDATE products SET calories = 123 WHERE IFNULL(calories, 0) = 0; /* Prevent invalid quantity unit assignments */ diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 5abc1ac2..ed52c0c5 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -178,8 +178,8 @@ @if($currentStockEntry->amount_opened > 0){{ $__t('%s opened', $currentStockEntry->amount_opened) }}@endif @if($currentStockEntry->is_aggregated_amount == 1) - {{ $currentStockEntry->amount_aggregated }} {{ $__n($currentStockEntry->amount_aggregated, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name_plural) }} - @if($currentStockEntry->amount_opened_aggregated > 0){{ $__t('%s opened', $currentStockEntry->amount_opened_aggregated) }}@endif + {{ $currentStockEntry->amount_aggregated }} {{ $__n($currentStockEntry->amount_aggregated, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name_plural) }} + @if($currentStockEntry->amount_opened_aggregated > 0){{ $__t('%s opened', $currentStockEntry->amount_opened_aggregated) }}@endif @endif