Added a user setting to automatically add missing products to the shopping list (closes #1266)

This commit is contained in:
Bernd Bestel 2022-04-03 13:00:14 +02:00
parent 34859ada02
commit a5294262e6
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
7 changed files with 56 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 ""

View File

@ -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();

View File

@ -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

View File

@ -27,6 +27,27 @@
{{ $__t('Show a month-view calendar') }}
</label>
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox"
class="form-check-input custom-control-input user-setting-control"
id="stock_auto_add_below_min_stock_amount_to_shopping_list"
data-setting-key="stock_auto_add_below_min_stock_amount_to_shopping_list">
<label class="form-check-label custom-control-label"
for="stock_auto_add_below_min_stock_amount_to_shopping_list">
{{ $__t('Automatically add products that are below their defined min. stock amount to the shopping list') }}
<select class="custom-control custom-select user-setting-control"
id="stock_auto_add_below_min_stock_amount_to_shopping_list_id"
data-setting-key="stock_auto_add_below_min_stock_amount_to_shopping_list_id"
@if(!boolval($userSettings['stock_auto_add_below_min_stock_amount_to_shopping_list']))
disabled
@endif>
@foreach($shoppingLists as $shoppingList)
<option value="{{ $shoppingList->id }}">{{ $shoppingList->name }}</option>
@endforeach
</select>
</label>
</div>
</div>
<h4 class="mt-2">{{ $__t('Shopping list to stock workflow') }}</h4>