Also show the product's default store on /stockoverview (closes #2698)

This commit is contained in:
Bernd Bestel 2025-03-10 17:36:23 +01:00
parent 6ca87a9a49
commit d1a8900f98
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 104 additions and 0 deletions

View File

@ -14,6 +14,7 @@
- A provided but empty localized product name is now ignored - A provided but empty localized product name is now ignored
- Non-ASCII characters in product names are now ignored (e.g. line breaks caused problems) - Non-ASCII characters in product names are now ignored (e.g. line breaks caused problems)
- Optimized that when an external barcode lookup plugin returned an image URL with query parameters, an invalid picture (file name) was added to the created product - Optimized that when an external barcode lookup plugin returned an image URL with query parameters, an invalid picture (file name) was added to the created product
- Added a new column "Default store" on the stock overview page (hidden by default)
### Shopping list ### Shopping list

98
migrations/0252.sql Normal file
View File

@ -0,0 +1,98 @@
DROP VIEW uihelper_stock_current_overview;
CREATE VIEW uihelper_stock_current_overview
AS
SELECT
p.id,
sc.amount_opened AS amount_opened,
p.tare_weight AS tare_weight,
p.enable_tare_weight_handling AS enable_tare_weight_handling,
sc.amount AS amount,
sc.value as value,
sc.product_id AS product_id,
IFNULL(sc.best_before_date, '2888-12-31') AS best_before_date,
EXISTS(SELECT id FROM stock_missing_products WHERE id = sc.product_id) AS product_missing,
p.name AS product_name,
pg.name AS product_group_name,
sl.name AS default_store_name,
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
qu_stock.name AS qu_stock_name,
qu_stock.name_plural AS qu_stock_name_plural,
qu_purchase.name AS qu_purchase_name,
qu_purchase.name_plural AS qu_purchase_name_plural,
qu_consume.name AS qu_consume_name,
qu_consume.name_plural AS qu_consume_name_plural,
qu_price.name AS qu_price_name,
qu_price.name_plural AS qu_price_name_plural,
sc.is_aggregated_amount,
sc.amount_opened_aggregated,
sc.amount_aggregated,
p.calories AS product_calories,
sc.amount * p.calories AS calories,
sc.amount_aggregated * p.calories AS calories_aggregated,
p.quick_consume_amount,
p.quick_consume_amount / p.qu_factor_consume_to_stock AS quick_consume_amount_qu_consume,
p.quick_open_amount,
p.quick_open_amount / p.qu_factor_consume_to_stock AS quick_open_amount_qu_consume,
p.due_type,
plp.purchased_date AS last_purchased,
plp.price AS last_price,
pap.price as average_price,
p.min_stock_amount,
pbcs.barcodes AS product_barcodes,
p.description AS product_description,
l.name AS product_default_location_name,
p_parent.id AS parent_product_id,
p_parent.name AS parent_product_name,
p.picture_file_name AS product_picture_file_name,
p.no_own_stock AS product_no_own_stock,
p.qu_factor_purchase_to_stock AS product_qu_factor_purchase_to_stock,
p.qu_factor_price_to_stock AS product_qu_factor_price_to_stock,
sc.is_in_stock_or_below_min_stock,
p.disable_open
FROM (
SELECT *, 1 AS is_in_stock_or_below_min_stock
FROM stock_current
WHERE best_before_date IS NOT NULL
UNION
SELECT m.id, 0, 0, 0, null, 0, 0, 0, p.due_type, 1 AS is_in_stock_or_below_min_stock
FROM stock_missing_products m
JOIN products p
ON m.id = p.id
WHERE m.id NOT IN (SELECT product_id FROM stock_current)
UNION
SELECT p2.id, 0, 0, 0, null, 0, 0, 0, p2.due_type, 0 AS is_in_stock_or_below_min_stock
FROM products p2
WHERE active = 1
AND p2.id NOT IN (SELECT product_id FROM stock_current UNION SELECT id FROM stock_missing_products)
) sc
JOIN products_view p
ON sc.product_id = p.id
JOIN locations l
ON p.location_id = l.id
JOIN quantity_units qu_stock
ON p.qu_id_stock = qu_stock.id
JOIN quantity_units qu_purchase
ON p.qu_id_purchase = qu_purchase.id
JOIN quantity_units qu_consume
ON p.qu_id_consume = qu_consume.id
JOIN quantity_units qu_price
ON p.qu_id_price = qu_price.id
LEFT JOIN product_groups pg
ON p.product_group_id = pg.id
LEFT JOIN shopping_locations sl
ON p.shopping_location_id = sl.id
LEFT JOIN cache__products_last_purchased plp
ON sc.product_id = plp.product_id
LEFT JOIN cache__products_average_price pap
ON sc.product_id = pap.product_id
LEFT JOIN product_barcodes_comma_separated pbcs
ON sc.product_id = pbcs.product_id
LEFT JOIN products p_parent
ON p.parent_product_id = p_parent.id
WHERE p.hide_on_stock_overview = 0;
DELETE FROM user_settings
WHERE key IN (
'datatables_state_stock-overview-tablee',
'datatables_rowGroup_stock-overview-table'
);

View File

@ -21,6 +21,7 @@ var stockOverviewTable = $('#stock-overview-table').DataTable({
{ 'visible': false, 'targets': 16 }, { 'visible': false, 'targets': 16 },
{ 'visible': false, 'targets': 17 }, { 'visible': false, 'targets': 17 },
{ 'visible': false, 'targets': 18 }, { 'visible': false, 'targets': 18 },
{ 'visible': false, 'targets': 19 },
{ "type": "custom-sort", "targets": 3 }, { "type": "custom-sort", "targets": 3 },
{ "type": "html-num-fmt", "targets": 9 }, { "type": "html-num-fmt", "targets": 9 },
{ "type": "html-num-fmt", "targets": 10 }, { "type": "html-num-fmt", "targets": 10 },

View File

@ -183,6 +183,7 @@
<th class="allow-grouping">{{ $__t('Default location') }}</th> <th class="allow-grouping">{{ $__t('Default location') }}</th>
<th>{{ $__t('Product picture') }}</th> <th>{{ $__t('Product picture') }}</th>
<th class="@if(!GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) d-none @endif">{{ $__t('Average price') }}</th> <th class="@if(!GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) d-none @endif">{{ $__t('Average price') }}</th>
<th class="@if(!GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) d-none @endif allow-grouping">{{ $__t('Default store') }}</th>
@include('components.userfields_thead', array( @include('components.userfields_thead', array(
'userfields' => $userfields 'userfields' => $userfields
@ -454,6 +455,9 @@
</span> </span>
@endif @endif
</td> </td>
<td>
@if($currentStockEntry->default_store_name !== null){{ $currentStockEntry->default_store_name }}@endif
</td>
@include('components.userfields_tbody', array( @include('components.userfields_tbody', array(
'userfields' => $userfields, 'userfields' => $userfields,