Finalized "Auto reprint stock entry label" (closes #2092)

This commit is contained in:
Bernd Bestel 2023-01-05 20:12:15 +01:00
parent 3b160659f3
commit 4e56dee6f0
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
6 changed files with 60 additions and 1 deletions

View File

@ -21,6 +21,9 @@
- Changed that when the ingredient option "Only check if any amount is in stock" is enabled, costs and calories are now based on the original entered amount instead of an "virtual" fixed amount of `1` - Changed that when the ingredient option "Only check if any amount is in stock" is enabled, costs and calories are now based on the original entered amount instead of an "virtual" fixed amount of `1`
- When using the "Add as barcode to existing product" workflow on a purchase transaction, the selected quantity unit and the entered amount is now also added to the new barcode - When using the "Add as barcode to existing product" workflow on a purchase transaction, the selected quantity unit and the entered amount is now also added to the new barcode
- When using the "Add as barcode to existing product" workflow on a purchase or inventory transaction, the entered note is now also added to the new barcode - When using the "Add as barcode to existing product" workflow on a purchase or inventory transaction, the entered note is now also added to the new barcode
- New product option "Auto reprint stock entry label"
- 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 (only server side label printer WebHooks are supported)
- 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) - 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 - This option will be automatically set on changing the entry's due date
- Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work - Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work

View File

@ -4468,6 +4468,9 @@
"treat_opened_as_out_of_stock": { "treat_opened_as_out_of_stock": {
"type": "integer" "type": "integer"
}, },
"auto_reprint_stock_label": {
"type": "integer"
},
"no_own_stock": { "no_own_stock": {
"type": "integer" "type": "integer"
}, },

View File

@ -2359,3 +2359,9 @@ msgstr ""
msgid "Reprint stock entry label" msgid "Reprint stock entry label"
msgstr "" msgstr ""
msgid "Auto reprint stock entry label"
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 ""

2
migrations/0212.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE products
ADD auto_reprint_stock_label TINYINT NOT NULL DEFAULT 0 CHECK(auto_reprint_stock_label IN (0, 1));

View File

@ -1013,6 +1013,22 @@ class StockService extends BaseService
{ {
$newBestBeforeDate = $stockEntry->best_before_date; $newBestBeforeDate = $stockEntry->best_before_date;
} }
if (GROCY_FEATURE_FLAG_LABEL_PRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $productDetails->product->auto_reprint_stock_label == 1 && $newBestBeforeDate != $stockEntry->best_before_date)
{
$webhookData = array_merge([
'product' => $productDetails->product->name,
'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])),
], GROCY_LABEL_PRINTER_PARAMS);
if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
{
$webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate;
}
$runner = new WebhookRunner();
$runner->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
}
} }
if ($allowSubproductSubstitution && $stockEntry->product_id != $productId) if ($allowSubproductSubstitution && $stockEntry->product_id != $productId)
@ -1292,7 +1308,6 @@ class StockService extends BaseService
} }
$newBestBeforeDate = $stockEntry->best_before_date; $newBestBeforeDate = $stockEntry->best_before_date;
if (GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING) if (GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING)
{ {
$locationFrom = $this->getDatabase()->locations()->where('id', $locationIdFrom)->fetch(); $locationFrom = $this->getDatabase()->locations()->where('id', $locationIdFrom)->fetch();
@ -1316,6 +1331,22 @@ class StockService extends BaseService
{ {
$newBestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_thawing . ' days')); $newBestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_thawing . ' days'));
} }
if (GROCY_FEATURE_FLAG_LABEL_PRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $productDetails->product->auto_reprint_stock_label == 1 && $stockEntry->best_before_date != $newBestBeforeDate)
{
$webhookData = array_merge([
'product' => $productDetails->product->name,
'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])),
], GROCY_LABEL_PRINTER_PARAMS);
if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
{
$webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate;
}
$runner = new WebhookRunner();
$runner->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
}
} }
$correlationId = uniqid(); $correlationId = uniqid();

View File

@ -521,6 +521,20 @@
intval($product->default_stock_label_type) == 2 ) selected="selected" @endif value="2">{{ $__t('Label per unit') }}</option> intval($product->default_stock_label_type) == 2 ) selected="selected" @endif value="2">{{ $__t('Label per unit') }}</option>
</select> </select>
</div> </div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input @if($mode=='edit'
&&
$product->auto_reprint_stock_label == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="auto_reprint_stock_label" name="auto_reprint_stock_label" value="1">
<label class="form-check-label custom-control-label"
for="auto_reprint_stock_label">{{ $__t('Auto reprint stock entry label') }}&nbsp;<i class="fa-solid fa-question-circle text-muted"
data-toggle="tooltip"
data-trigger="hover click"
title="{{ $__t('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') }}"></i>
</label>
</div>
</div>
@endif @endif
@include('components.userfieldsform', array( @include('components.userfieldsform', array(