Fixed consume page location dropdown handling (fixes #2328)

This commit is contained in:
Bernd Bestel 2023-09-02 10:17:43 +02:00
parent b2295ce6d2
commit b0d6e24bd4
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 77 additions and 11 deletions

View File

@ -0,0 +1,57 @@
> ⚠️ xxxBREAKING CHANGESxxx
> ❗ xxxImportant upgrade informationXXX
> 💡 xxxMinor upgrade informationXXX
### New feature: xxxx
- xxx
### Stock
- Fixed that the location dropdown on the consume page contained the same location multiple times if there are currently stock entries at multiple locations of the corresponding product
### Shopping list
- xxx
### Recipes
- xxx
### Meal plan
- xxx
### Chores
- xxx
### Calendar
- xxx
### Tasks
- xxx
### Batteries
- xxx
### Equipment
- xxx
### Userfields
- xxx
### General
- xxx
### API
- xxx

View File

@ -389,9 +389,12 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
var setDefault = 0; var setDefault = 0;
var stockAmountAtDefaultLocation = 0; var stockAmountAtDefaultLocation = 0;
var addedLocations = [];
stockLocations.forEach(stockLocation => stockLocations.forEach(stockLocation =>
{ {
if (stockLocation.location_id == defaultLocationId) if (stockLocation.location_id == defaultLocationId)
{
if (!addedLocations.includes(stockLocation.location_id))
{ {
$("#location_id").append($("<option>", { $("#location_id").append($("<option>", {
value: stockLocation.location_id, value: stockLocation.location_id,
@ -400,15 +403,21 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
$("#location_id").val(defaultLocationId); $("#location_id").val(defaultLocationId);
$("#location_id").trigger('change'); $("#location_id").trigger('change');
setDefault = 1; setDefault = 1;
}
stockAmountAtDefaultLocation += stockLocation.amount; stockAmountAtDefaultLocation += stockLocation.amount;
} }
else else
{
if (!addedLocations.includes(stockLocation.location_id))
{ {
$("#location_id").append($("<option>", { $("#location_id").append($("<option>", {
value: stockLocation.location_id, value: stockLocation.location_id,
text: stockLocation.location_name text: stockLocation.location_name
})); }));
} }
}
addedLocations.push(stockLocation.location_id);
if (setDefault == 0) if (setDefault == 0)
{ {