Split the quick consume and open amount product option (closes #2127)

This commit is contained in:
Bernd Bestel 2023-02-05 20:37:39 +01:00
parent b64d726c42
commit d8d3c3ef0b
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
8 changed files with 126 additions and 8 deletions

View File

@ -26,6 +26,7 @@
- Defaults to disabled, so no changed behavior when not configured
- Added a new option "Reprint stock entry label" on the stock entry edit page (will print the correspondind stock entry label on save)
- This option will be automatically set on changing the entry's due date
- The product option "Quick consume amount" (the amount used for the "quick consume/open buttons" on the stock overview page) has been split into another option "Quick open amount", to be able to set different amounts for consume and open (defaults to the "Quick consume amount" per product, so no changed behavior when not configured)
- Changed that for the product's average and last price (and for the price history chart) stock transactions with an empty or `0` price are ignored
- Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work
- Fixed that sorting by the "Value" column on the stock overview page didn't work

View File

@ -1793,7 +1793,10 @@ msgstr ""
msgid "Quick consume amount"
msgstr ""
msgid "This amount is used for the \"quick consume/open buttons\" on the stock overview page (related to quantity unit stock)"
msgid "This amount is used for the \"quick consume button\" on the stock overview page (related to quantity unit stock)"
msgstr ""
msgid "This amount is used for the \"quick open button\" on the stock overview page (related to quantity unit stock)"
msgstr ""
msgid "Copy"
@ -2365,3 +2368,6 @@ msgstr ""
msgid "When enabled, auto-changing the due date of a stock entry (by opening/freezing/thawing and having corresponding default due days set) will reprint its label"
msgstr ""
msgid "Quick open amount"
msgstr ""

View File

@ -1,7 +1,7 @@
CREATE TRIGGER cascade_change_qu_id_stock2 AFTER UPDATE ON products WHEN NEW.qu_id_stock != OLD.qu_id_stock
BEGIN
-- See also the trigger "cascade_change_qu_id_stock BEFORE UPDATE ON products"
-- This here applies the needed changes to the products table itself only AFTER the udpate
-- This here applies the needed changes to the products table itself only AFTER the update
UPDATE products
SET quick_consume_amount = quick_consume_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0),

View File

@ -251,7 +251,7 @@ END;
CREATE TRIGGER cascade_change_qu_id_stock2 AFTER UPDATE ON products WHEN NEW.qu_id_stock != OLD.qu_id_stock
BEGIN
-- See also the trigger "cascade_change_qu_id_stock BEFORE UPDATE ON products"
-- This here applies the needed changes to the products table itself only AFTER the udpate
-- This here applies the needed changes to the products table itself only AFTER the update
UPDATE products
SET quick_consume_amount = quick_consume_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0),

97
migrations/0214.sql Normal file
View File

@ -0,0 +1,97 @@
ALTER TABLE products
ADD quick_open_amount REAL NOT NULL DEFAULT 1;
UPDATE products
SET quick_open_amount= quick_consume_amount;
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,
sc.best_before_date 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,
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,
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
FROM (
SELECT *
FROM stock_current
WHERE best_before_date IS NOT NULL
UNION
SELECT m.id, 0, 0, 0, null, 0, 0, 0, p.due_type
FROM stock_missing_products m
JOIN products p
ON m.id = p.id
WHERE m.id NOT IN (SELECT product_id FROM stock_current)
) 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
LEFT JOIN product_groups pg
ON p.product_group_id = pg.id
LEFT JOIN products_last_purchased plp
ON sc.product_id = plp.product_id
LEFT JOIN 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;
DROP TRIGGER cascade_change_qu_id_stock2;
CREATE TRIGGER cascade_change_qu_id_stock2 AFTER UPDATE ON products WHEN NEW.qu_id_stock != OLD.qu_id_stock
BEGIN
-- See also the trigger "cascade_change_qu_id_stock BEFORE UPDATE ON products"
-- This here applies the needed changes to the products table itself only AFTER the update
UPDATE products
SET quick_consume_amount = quick_consume_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0),
quick_open_amount = quick_open_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0),
calories = calories / IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0),
tare_weight = tare_weight * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock LIMIT 1), 1.0)
WHERE id = NEW.id;
END;

View File

@ -161,6 +161,7 @@ $('.input-group-qu').on('change', function(e)
{
$("#tare_weight_qu_info").text($("#qu_id_stock option:selected").text());
$("#quick_consume_qu_info").text($("#qu_id_stock option:selected").text());
$("#quick_open_qu_info").text($("#qu_id_stock option:selected").text());
$("#energy_qu_info").text(Grocy.EnergyUnit + " / " + $("#qu_id_stock option:selected").text());
Grocy.FrontendHelpers.ValidateForm('product-form');
@ -433,6 +434,7 @@ if (Grocy.EditMode == "create" && GetUriParam("copy-of") != undefined)
$("#default_best_before_days_after_freezing").val(sourceProduct.default_best_before_days_after_freezing);
$("#default_best_before_days_after_thawing").val(sourceProduct.default_best_before_days_after_thawing);
$("#quick_consume_amount").val(sourceProduct.quick_consume_amount);
$("#quick_open_amount").val(sourceProduct.quick_open_amount);
Grocy.FrontendHelpers.ValidateForm('product-form');
},

View File

@ -495,10 +495,22 @@
'min' => $DEFAULT_MIN_AMOUNT,
'decimals' => $userSettings['stock_decimal_places_amounts'],
'value' => $value,
'hint' => $__t('This amount is used for the "quick consume/open buttons" on the stock overview page (related to quantity unit stock)'),
'hint' => $__t('This amount is used for the "quick consume button" on the stock overview page (related to quantity unit stock)'),
'contextInfoId' => 'quick_consume_qu_info',
'additionalCssClasses' => 'locale-number-input locale-number-quantity-amount'
))
@php if($mode == 'edit') { $value = $product->quick_open_amount; } else { $value = 1; } @endphp
@include('components.numberpicker', array(
'id' => 'quick_open_amount',
'label' => 'Quick open amount',
'min' => $DEFAULT_MIN_AMOUNT,
'decimals' => $userSettings['stock_decimal_places_amounts'],
'value' => $value,
'hint' => $__t('This amount is used for the "quick open button" on the stock overview page (related to quantity unit stock)'),
'contextInfoId' => 'quick_open_qu_info',
'additionalCssClasses' => 'locale-number-input locale-number-quantity-amount'
))
@if(GROCY_FEATURE_FLAG_LABEL_PRINTER)
<div class="form-group">

View File

@ -213,16 +213,16 @@
<i class="fa-solid fa-utensils"></i> {{ $__t('All') }}
</a>
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING)
<a class="btn btn-success btn-sm product-open-button @if($currentStockEntry->amount_aggregated < $currentStockEntry->quick_consume_amount || $currentStockEntry->amount_aggregated == $currentStockEntry->amount_opened_aggregated || $currentStockEntry->enable_tare_weight_handling == 1) disabled @endif"
<a class="btn btn-success btn-sm product-open-button @if($currentStockEntry->amount_aggregated < $currentStockEntry->quick_open_amount || $currentStockEntry->amount_aggregated == $currentStockEntry->amount_opened_aggregated || $currentStockEntry->enable_tare_weight_handling == 1) disabled @endif"
href="#"
data-toggle="tooltip"
data-placement="left"
title="{{ $__t('Mark %1$s of %2$s as open', floatval($currentStockEntry->quick_consume_amount_qu_consume) . ' ' . $currentStockEntry->qu_consume_name, $currentStockEntry->product_name) }}"
title="{{ $__t('Mark %1$s of %2$s as open', floatval($currentStockEntry->quick_open_amount_qu_consume) . ' ' . $currentStockEntry->qu_consume_name, $currentStockEntry->product_name) }}"
data-product-id="{{ $currentStockEntry->product_id }}"
data-product-name="{{ $currentStockEntry->product_name }}"
data-product-qu-name="{{ $currentStockEntry->qu_stock_name }}"
data-open-amount="{{ $currentStockEntry->quick_consume_amount }}">
<i class="fa-solid fa-box-open"></i> <span class="locale-number locale-number-quantity-amount">{{ $currentStockEntry->quick_consume_amount_qu_consume }}</span>
data-open-amount="{{ $currentStockEntry->quick_open_amount }}">
<i class="fa-solid fa-box-open"></i> <span class="locale-number locale-number-quantity-amount">{{ $currentStockEntry->quick_open_amount_qu_consume }}</span>
</a>
@endif
<div class="dropdown d-inline-block">