diff --git a/changelog/67_UNRELEASED_xxxx-xx-xx.md b/changelog/67_UNRELEASED_xxxx-xx-xx.md index b16765a4..d7814cb5 100644 --- a/changelog/67_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/67_UNRELEASED_xxxx-xx-xx.md @@ -39,6 +39,7 @@ ### Shopping list +- Added a new shopping list setting (top right corner settings menu) to automatically add products, that are below their defined min. stock amount, to the shopping list - Fixed that when using "Add products that are below defined min. stock amount", the calculated missing amount was wrong for products which had the new product option `Treat opened as out of stock` set and when having at least one opened stock entry ### Recipes diff --git a/config-dist.php b/config-dist.php index 90a2127c..ad75cfd0 100644 --- a/config-dist.php +++ b/config-dist.php @@ -149,8 +149,8 @@ Setting('FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA', true); // Enables the torch au // Default user settings -// These settings can be changed per user, below here are the defaults -// which are used when the user has not changed the setting so far +// These settings can be changed per user and via the UI, +// below are the defaults which are used when the user has not changed the setting so far // Night mode related DefaultUserSetting('night_mode', 'follow-system'); // "on" = Night mode is always on ; "off" = Night mode is always off / "follow-system" = System preferred color schema is used @@ -183,6 +183,8 @@ DefaultUserSetting('scan_mode_purchase_enabled', false); // If scan mode on the DefaultUserSetting('show_icon_on_stock_overview_page_when_product_is_on_shopping_list', true); // When enabled, an icon is shown on the stock overview page (next to the product name) when the prodcut is currently on a shopping list DefaultUserSetting('show_purchased_date_on_purchase', false); // Whether the purchased date should be editable on purchase (defaults to today otherwise) DefaultUserSetting('show_warning_on_purchase_when_due_date_is_earlier_than_next', true); // Show a warning on purchase when the due date of the purchased product is earlier than the next due date in stock +DefaultUserSetting('stock_auto_add_below_min_stock_amount_to_shopping_list', false); // If products should be automatically added to the shopping list when they are below their min. stock amount +DefaultUserSetting('stock_auto_add_below_min_stock_amount_to_shopping_list_id', 1); // When the above setting is enabled, the id of the shopping list to which the products will be added // Shopping list settings DefaultUserSetting('shopping_list_to_stock_workflow_auto_submit_when_prefilled', false); // Automatically do the booking using the last price and the amount of the shopping list item, if the product has "Default due days" set diff --git a/controllers/StockController.php b/controllers/StockController.php index 1d39a037..f9a3a1f9 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -423,7 +423,9 @@ class StockController extends BaseController public function ShoppingListSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { - return $this->renderPage($response, 'shoppinglistsettings'); + return $this->renderPage($response, 'shoppinglistsettings', [ + 'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE') + ]); } public function ShoppingLocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) diff --git a/localization/strings.pot b/localization/strings.pot index f5f089ec..2d70954b 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2350,3 +2350,6 @@ msgstr "" msgid "Off" msgstr "" + +msgid "Automatically add products that are below their defined min. stock amount to the shopping list" +msgstr "" diff --git a/public/viewjs/shoppinglistsettings.js b/public/viewjs/shoppinglistsettings.js index 1e5e86d8..abaecbd9 100644 --- a/public/viewjs/shoppinglistsettings.js +++ b/public/viewjs/shoppinglistsettings.js @@ -8,4 +8,23 @@ if (BoolVal(Grocy.UserSettings.shopping_list_show_calendar)) $("#shopping_list_show_calendar").prop("checked", true); } +if (BoolVal(Grocy.UserSettings.stock_auto_add_below_min_stock_amount_to_shopping_list)) +{ + $("#stock_auto_add_below_min_stock_amount_to_shopping_list").prop("checked", true); +} + +$("#stock_auto_add_below_min_stock_amount_to_shopping_list_id").val(Grocy.UserSettings.stock_auto_add_below_min_stock_amount_to_shopping_list_id); + +$("#stock_auto_add_below_min_stock_amount_to_shopping_list").on("click", function() +{ + if (this.checked) + { + $("#stock_auto_add_below_min_stock_amount_to_shopping_list_id").removeAttr("disabled"); + } + else + { + $("#stock_auto_add_below_min_stock_amount_to_shopping_list_id").attr("disabled", ""); + } +}); + RefreshLocaleNumberInput(); diff --git a/services/StockService.php b/services/StockService.php index b16b540c..59ffa9c5 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -498,6 +498,11 @@ class StockService extends BaseService $this->CompactStockEntries($productId); + if (boolval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'stock_auto_add_below_min_stock_amount_to_shopping_list'))) + { + $this->AddMissingProductsToShoppingList(intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'stock_auto_add_below_min_stock_amount_to_shopping_list_id'))); + } + return $transactionId; } else diff --git a/views/shoppinglistsettings.blade.php b/views/shoppinglistsettings.blade.php index ebdc3166..5f0400c7 100644 --- a/views/shoppinglistsettings.blade.php +++ b/views/shoppinglistsettings.blade.php @@ -27,6 +27,27 @@ {{ $__t('Show a month-view calendar') }} + +
+ + +

{{ $__t('Shopping list to stock workflow') }}