From 247221950da02ef1be1d524e6741bf8f3e12cadb Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 12 Jul 2021 17:56:09 +0200 Subject: [PATCH] Never extend the original due date on when opening a product which has default_best_before_days (closes #1342) --- changelog/62_UNRELEASED_xxxx-xx-xx.md | 1 + localization/strings.pot | 2 +- services/StockService.php | 6 ++++++ views/productform.blade.php | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index b3e3ccea..2b9c868c 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -33,6 +33,7 @@ - The product picker on the consume and transfer page now only shows products which are currently in stock - Added a filter option to only show in-stock products on the products list page (master data) - Added new columns on the stock overview page (hidden by default): Product description, product default location, parent product +- Optimized that when opening a product which has "Default due days after opened" set, the resulting date now never extends the original due date - Fixed that editing stock entries was not possible - Fixed that consuming with Scan Mode was not possible - Fixed that the current stock total value (header of the stock overview page) didn't include decimal amounts (thanks @Ape) diff --git a/localization/strings.pot b/localization/strings.pot index 468e5db2..b941ef1b 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1903,7 +1903,7 @@ msgstr "" msgid "Default due days" msgstr "" -msgid "When this product was marked as opened, the due date will be replaced by today + this amount of days (a value of 0 disables this)" +msgid "When this product was marked as opened, the due date will be replaced by today + this amount of days, but only if the resulting date is not after the original due date (a value of 0 disables this)" msgstr "" msgid "Default due days after opened" diff --git a/services/StockService.php b/services/StockService.php index a43dc177..2088fb8a 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -891,6 +891,12 @@ class StockService extends BaseService if ($product->default_best_before_days_after_open > 0) { $newBestBeforeDate = date('Y-m-d', strtotime('+' . $product->default_best_before_days_after_open . ' days')); + + // The new due date should be never > the original due date + if (strtotime($newBestBeforeDate) > strtotime($stockEntry->best_before_date)) + { + $newBestBeforeDate = $stockEntry->best_before_date; + } } if ($allowSubproductSubstitution && $stockEntry->product_id != $productId) diff --git a/views/productform.blade.php b/views/productform.blade.php index 9c53393a..2860ff64 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -212,7 +212,7 @@ 'label' => 'Default due days after opened', 'min' => 0, 'value' => $value, - 'hint' => $__t('When this product was marked as opened, the due date will be replaced by today + this amount of days (a value of 0 disables this)') + 'hint' => $__t('When this product was marked as opened, the due date will be replaced by today + this amount of days, but only if the resulting date is not after the original due date (a value of 0 disables this)') )) @else