mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Simplified stock entry label printing options (on purchase) (references #1647)
This commit is contained in:
parent
89b87156de
commit
fc413a05d1
@ -2095,6 +2095,9 @@ msgstr ""
|
||||
msgid "Print on label printer"
|
||||
msgstr ""
|
||||
|
||||
msgid "Default stock entry label"
|
||||
msgstr ""
|
||||
|
||||
msgid "Stock entry label"
|
||||
msgstr ""
|
||||
|
||||
@ -2107,12 +2110,6 @@ msgstr ""
|
||||
msgid "Label per unit"
|
||||
msgstr ""
|
||||
|
||||
msgid "Allow label printing per unit"
|
||||
msgstr ""
|
||||
|
||||
msgid "Allow printing of one label per unit on purchase (after conversion) - e.g. 1 purchased pack adding 10 pieces of stock would print 10 labels"
|
||||
msgstr ""
|
||||
|
||||
msgid "Error while executing WebHook"
|
||||
msgstr ""
|
||||
|
||||
@ -2244,3 +2241,6 @@ msgstr ""
|
||||
|
||||
msgid "Are you sure to empty the shopping list?"
|
||||
msgstr ""
|
||||
|
||||
msgid "This is the default which will be prefilled on purchase"
|
||||
msgstr ""
|
||||
|
158
migrations/0155.sql
Normal file
158
migrations/0155.sql
Normal file
@ -0,0 +1,158 @@
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
ALTER TABLE products RENAME TO products_old;
|
||||
|
||||
-- Remove allow_label_per_unit column
|
||||
CREATE TABLE products (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
product_group_id INTEGER,
|
||||
active TINYINT NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
location_id INTEGER NOT NULL,
|
||||
shopping_location_id INTEGER,
|
||||
qu_id_purchase INTEGER NOT NULL,
|
||||
qu_id_stock INTEGER NOT NULL,
|
||||
qu_factor_purchase_to_stock REAL NOT NULL,
|
||||
min_stock_amount INTEGER NOT NULL DEFAULT 0,
|
||||
default_best_before_days INTEGER NOT NULL DEFAULT 0,
|
||||
default_best_before_days_after_open INTEGER NOT NULL DEFAULT 0,
|
||||
default_best_before_days_after_freezing INTEGER NOT NULL DEFAULT 0,
|
||||
default_best_before_days_after_thawing INTEGER NOT NULL DEFAULT 0,
|
||||
picture_file_name TEXT,
|
||||
enable_tare_weight_handling TINYINT NOT NULL DEFAULT 0,
|
||||
tare_weight REAL NOT NULL DEFAULT 0,
|
||||
not_check_stock_fulfillment_for_recipes TINYINT DEFAULT 0,
|
||||
parent_product_id INT,
|
||||
calories INTEGER,
|
||||
cumulate_min_stock_amount_of_sub_products TINYINT DEFAULT 0,
|
||||
due_type TINYINT NOT NULL DEFAULT 1 CHECK(due_type IN (1, 2)),
|
||||
quick_consume_amount REAL NOT NULL DEFAULT 1,
|
||||
hide_on_stock_overview TINYINT NOT NULL DEFAULT 0 CHECK(hide_on_stock_overview IN (0, 1)),
|
||||
default_print_stock_label INTEGER NOT NULL DEFAULT 0,
|
||||
should_not_be_frozen TINYINT NOT NULL DEFAULT 0 CHECK(should_not_be_frozen IN (0, 1)),
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
|
||||
INSERT INTO products
|
||||
(id, name, description, product_group_id, active, location_id, shopping_location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, default_best_before_days, default_best_before_days_after_open, default_best_before_days_after_freezing, default_best_before_days_after_thawing, picture_file_name, enable_tare_weight_handling, tare_weight, not_check_stock_fulfillment_for_recipes, parent_product_id, calories, cumulate_min_stock_amount_of_sub_products, due_type, quick_consume_amount, hide_on_stock_overview, default_print_stock_label, should_not_be_frozen, row_created_timestamp)
|
||||
SELECT id, name, description, product_group_id, active, location_id, shopping_location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, default_best_before_days, default_best_before_days_after_open, default_best_before_days_after_freezing, default_best_before_days_after_thawing, picture_file_name, enable_tare_weight_handling, tare_weight, not_check_stock_fulfillment_for_recipes, parent_product_id, calories, cumulate_min_stock_amount_of_sub_products, due_type, quick_consume_amount, hide_on_stock_overview, default_print_stock_label, should_not_be_frozen, row_created_timestamp
|
||||
FROM products_old;
|
||||
|
||||
DROP TABLE products_old;
|
||||
|
||||
CREATE TRIGGER prevent_qu_stock_change_after_first_purchase AFTER UPDATE ON products
|
||||
BEGIN
|
||||
SELECT CASE WHEN((
|
||||
SELECT 1
|
||||
FROM stock_log
|
||||
WHERE product_id = NEW.id
|
||||
AND NEW.qu_id_stock != OLD.qu_id_stock
|
||||
) NOTNULL) THEN RAISE(ABORT, "qu_id_stock cannot be changed when the product was once added to stock") END;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER enforce_parent_product_id_null_when_empty_INS AFTER INSERT ON products
|
||||
BEGIN
|
||||
UPDATE products
|
||||
SET parent_product_id = NULL
|
||||
WHERE id = NEW.id
|
||||
AND IFNULL(parent_product_id, '') = '';
|
||||
END;
|
||||
|
||||
CREATE TRIGGER enforce_parent_product_id_null_when_empty_UPD AFTER UPDATE ON products
|
||||
BEGIN
|
||||
UPDATE products
|
||||
SET parent_product_id = NULL
|
||||
WHERE id = NEW.id
|
||||
AND IFNULL(parent_product_id, '') = '';
|
||||
END;
|
||||
|
||||
CREATE TRIGGER cascade_product_removal AFTER DELETE ON products
|
||||
BEGIN
|
||||
DELETE FROM stock
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
DELETE FROM stock_log
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
DELETE FROM product_barcodes
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
DELETE FROM quantity_unit_conversions
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
DELETE FROM recipes_pos
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
UPDATE recipes
|
||||
SET product_id = NULL
|
||||
WHERE product_id = OLD.id;
|
||||
|
||||
DELETE FROM meal_plan
|
||||
WHERE product_id = OLD.id
|
||||
AND type = 'product';
|
||||
|
||||
DELETE FROM shopping_list
|
||||
WHERE product_id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER enfore_product_nesting_level BEFORE UPDATE ON products
|
||||
BEGIN
|
||||
-- Currently only 1 level is supported
|
||||
SELECT CASE WHEN((
|
||||
SELECT 1
|
||||
FROM products p
|
||||
WHERE IFNULL(NEW.parent_product_id, '') != ''
|
||||
AND IFNULL(parent_product_id, '') = NEW.id
|
||||
) NOTNULL) THEN RAISE(ABORT, "Unsupported product nesting level detected (currently only 1 level is supported)") END;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER enforce_min_stock_amount_for_cumulated_childs_INS AFTER INSERT ON products
|
||||
BEGIN
|
||||
/*
|
||||
When a parent product has cumulate_min_stock_amount_of_sub_products enabled,
|
||||
the child should not have any min_stock_amount
|
||||
*/
|
||||
|
||||
UPDATE products
|
||||
SET min_stock_amount = 0
|
||||
WHERE id IN (
|
||||
SELECT
|
||||
p_child.id
|
||||
FROM products p_parent
|
||||
JOIN products p_child
|
||||
ON p_child.parent_product_id = p_parent.id
|
||||
WHERE p_parent.id = NEW.id
|
||||
AND IFNULL(p_parent.cumulate_min_stock_amount_of_sub_products, 0) = 1
|
||||
)
|
||||
AND min_stock_amount > 0;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER enforce_min_stock_amount_for_cumulated_childs_UPD AFTER UPDATE ON products
|
||||
BEGIN
|
||||
/*
|
||||
When a parent product has cumulate_min_stock_amount_of_sub_products enabled,
|
||||
the child should not have any min_stock_amount
|
||||
*/
|
||||
|
||||
UPDATE products
|
||||
SET min_stock_amount = 0
|
||||
WHERE id IN (
|
||||
SELECT
|
||||
p_child.id
|
||||
FROM products p_parent
|
||||
JOIN products p_child
|
||||
ON p_child.parent_product_id = p_parent.id
|
||||
WHERE p_parent.id = NEW.id
|
||||
AND IFNULL(p_parent.cumulate_min_stock_amount_of_sub_products, 0) = 1
|
||||
)
|
||||
AND min_stock_amount > 0;
|
||||
END;
|
||||
|
||||
CREATE INDEX ix_products_performance1 ON products (
|
||||
parent_product_id
|
||||
);
|
||||
|
||||
CREATE INDEX ix_products_performance2 ON products (
|
||||
CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END,
|
||||
active
|
||||
);
|
@ -405,22 +405,6 @@ $('#qu_id_stock').change(function(e)
|
||||
}
|
||||
});
|
||||
|
||||
$('#allow_label_per_unit').on('change', function()
|
||||
{
|
||||
if (this.checked)
|
||||
{
|
||||
$('#label-option-per-unit').prop("disabled", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($('#default_print_stock_label').val() == "2")
|
||||
{
|
||||
$("#default_print_stock_label").val("0");
|
||||
}
|
||||
$('#label-option-per-unit').prop("disabled", true);
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on("message", function(e)
|
||||
{
|
||||
var data = e.originalEvent.data;
|
||||
|
@ -185,6 +185,10 @@ $('#save-purchase-button').on('click', function(e)
|
||||
}
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
Grocy.Components.ProductCard.Refresh(jsonForm.product_id);
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER)
|
||||
{
|
||||
$("#print_stock_label").val(0);
|
||||
}
|
||||
|
||||
$('#price-hint').text("");
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
@ -291,18 +295,6 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER)
|
||||
{
|
||||
$("#print_stock_label").val(productDetails.product.default_print_stock_label);
|
||||
if (productDetails.product.allow_label_per_unit)
|
||||
{
|
||||
if ($('#default_print_stock_label').val() == "2")
|
||||
{
|
||||
$("#default_print_stock_label").val("0");
|
||||
}
|
||||
$('#label-option-per-unit').prop("disabled", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#label-option-per-unit').prop("disabled", false);
|
||||
}
|
||||
}
|
||||
|
||||
$("#display_amount").focus();
|
||||
|
@ -447,60 +447,23 @@
|
||||
|
||||
@if(GROCY_FEATURE_FLAG_LABEL_PRINTER)
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input @if($mode=='edit'
|
||||
&&
|
||||
$product->allow_label_per_unit == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="allow_label_per_unit" name="allow_label_per_unit" value="1">
|
||||
<label class="form-check-label custom-control-label"
|
||||
for="allow_label_per_unit">{{ $__t('Allow label printing per unit') }} <i class="fas fa-question-circle text-muted"
|
||||
<label for="default_print_stock_label">{{ $__t('Default stock entry label') }}</label>
|
||||
<i class="fas fa-question-circle text-muted"
|
||||
data-toggle="tooltip"
|
||||
data-trigger="hover click"
|
||||
title="{{ $__t('Allow printing of one label per unit on purchase (after conversion) - e.g. 1 purchased pack adding 10 pieces of stock would print 10 labels') }}"></i>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@php
|
||||
$no_label = "";
|
||||
$single_label = "";
|
||||
$per_unit_label = "";
|
||||
$disable_per_unit = "";
|
||||
|
||||
if($mode == 'edit') {
|
||||
switch($product->default_print_stock_label) {
|
||||
case 0: $no_label = "selected"; break;
|
||||
case 1: $single_label = "selected"; break;
|
||||
case 2: $per_unit_label = "selected"; break;
|
||||
default: break; // yolo
|
||||
}
|
||||
if($product->allow_label_per_unit == 0) {
|
||||
$disable_per_unit="disabled";
|
||||
$per_unit_label = "";
|
||||
}
|
||||
}
|
||||
@endphp
|
||||
|
||||
<div class="form-group">
|
||||
<label for="default_print_stock_label">{{ $__t('Stock entry label') }}</label>
|
||||
title="{{ $__t('This is the default which will be prefilled on purchase') }}"></i>
|
||||
<select class="form-control"
|
||||
id="default_print_stock_label"
|
||||
name="default_print_stock_label">
|
||||
<option value="0"
|
||||
{{
|
||||
$no_label
|
||||
}}>{{ $__t('No label') }}</option>
|
||||
<option value="1"
|
||||
{{
|
||||
$single_label
|
||||
}}>{{ $__t('Single label') }}</option>
|
||||
<option value="2"
|
||||
{{
|
||||
$per_unit_label
|
||||
}}
|
||||
{{
|
||||
$disable_per_unit
|
||||
}}
|
||||
id="label-option-per-unit">{{ $__t('Label per unit') }}</option>
|
||||
<option @if($mode=='edit'
|
||||
&&
|
||||
intval($product->default_print_stock_label) == 0 ) selected="selected" @endif value="0">{{ $__t('No label') }}</option>
|
||||
<option @if($mode=='edit'
|
||||
&&
|
||||
intval($product->default_print_stock_label) == 1 ) selected="selected" @endif value="1">{{ $__t('Single label') }}</option>
|
||||
<option @if($mode=='edit'
|
||||
&&
|
||||
intval($product->default_print_stock_label) == 2 ) selected="selected" @endif value="2">{{ $__t('Label per unit') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@endif
|
||||
|
@ -156,8 +156,7 @@
|
||||
name="print_stock_label">
|
||||
<option value="0">{{ $__t('No label') }}</option>
|
||||
<option value="1">{{ $__t('Single label') }}</option>
|
||||
<option value="2"
|
||||
id="label-option-per-unit">{{ $__t('Label per unit') }}</option>
|
||||
<option value="2">{{ $__t('Label per unit') }}</option>
|
||||
</select>
|
||||
<div class="invalid-feedback">{{ $__t('A quantity unit is required') }}</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user