diff --git a/controllers/StockController.php b/controllers/StockController.php index bf3e4e7d..f42546e6 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -179,6 +179,7 @@ class StockController extends BaseController return $this->renderPage($response, 'productform', [ 'locations' => $this->getDatabase()->locations()->orderBy('name'), 'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'), + 'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'), 'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'), 'userfields' => $this->getUserfieldsService()->GetFields('products'), 'products' => $this->getDatabase()->products()->where('parent_product_id IS NULL')->orderBy('name'), @@ -194,6 +195,7 @@ class StockController extends BaseController 'product' => $product, 'locations' => $this->getDatabase()->locations()->orderBy('name'), 'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'), + 'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'), 'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'), 'userfields' => $this->getUserfieldsService()->GetFields('products'), 'products' => $this->getDatabase()->products()->where('id != :1 AND parent_product_id IS NULL', $product->id)->orderBy('name'), diff --git a/grocy.openapi.json b/grocy.openapi.json index be1bdb71..3797efd3 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -3435,6 +3435,9 @@ "row_created_timestamp": { "type": "string", "format": "date-time" + }, + "shopping_location_id": { + "type": "integer" } }, "example": { @@ -3455,7 +3458,8 @@ "allow_partial_units_in_stock": "0", "enable_tare_weight_handling": "0", "tare_weight": "0.0", - "not_check_stock_fulfillment_for_recipes": "0" + "not_check_stock_fulfillment_for_recipes": "0", + "shopping_location_id": null } }, "QuantityUnit": { @@ -3724,7 +3728,8 @@ "allow_partial_units_in_stock": "0", "enable_tare_weight_handling": "0", "tare_weight": "0.0", - "not_check_stock_fulfillment_for_recipes": "0" + "not_check_stock_fulfillment_for_recipes": "0", + "last_shopping_location_id": null }, "last_purchased": null, "last_used": null, diff --git a/migrations/0099.sql b/migrations/0099.sql index d35f069e..b7d90f92 100644 --- a/migrations/0099.sql +++ b/migrations/0099.sql @@ -11,6 +11,9 @@ ADD shopping_location_id INTEGER; ALTER TABLE stock ADD shopping_location_id INTEGER; +ALTER TABLE products +ADD shopping_location_id INTEGER; + DROP VIEW stock_current_locations; CREATE VIEW stock_current_locations AS diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 0ed915df..e4e8e3b3 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -140,7 +140,16 @@ if (Grocy.Components.ProductPicker !== undefined) function(productDetails) { $('#price').val(productDetails.last_price); - Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); + + if (productDetails.last_shopping_location_id != null) + { + Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); + } + else + { + Grocy.Components.ShoppingLocationPicker.SetId(productDetails.default_shopping_location_id); + } + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { Grocy.Components.LocationPicker.SetId(productDetails.location.id); diff --git a/services/StockService.php b/services/StockService.php index 02c1e0a1..2b794bf2 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -127,6 +127,7 @@ class StockService extends BaseService $averageShelfLifeDays = intval($this->getDatabase()->stock_average_product_shelf_life()->where('id', $productId)->fetch()->average_shelf_life_days); $lastPrice = null; + $defaultShoppingLocation = null; $lastShoppingLocation = null; $lastLogRow = $this->getDatabase()->stock_log()->where('product_id = :1 AND transaction_type IN (:2, :3) AND undone = 0', $productId, self::TRANSACTION_TYPE_PURCHASE, self::TRANSACTION_TYPE_INVENTORY_CORRECTION)->orderBy('row_created_timestamp', 'DESC')->limit(1)->fetch(); if ($lastLogRow !== null && !empty($lastLogRow)) @@ -155,6 +156,7 @@ class StockService extends BaseService 'quantity_unit_stock' => $quStock, 'last_price' => $lastPrice, 'last_shopping_location_id' => $lastShoppingLocation, + 'default_shopping_location_id' => $product->shopping_location_id, 'next_best_before_date' => $nextBestBeforeDate, 'location' => $location, 'average_shelf_life_days' => $averageShelfLifeDays, diff --git a/views/components/shoppinglocationpicker.blade.php b/views/components/shoppinglocationpicker.blade.php index f3ccf237..83aaf767 100644 --- a/views/components/shoppinglocationpicker.blade.php +++ b/views/components/shoppinglocationpicker.blade.php @@ -9,7 +9,7 @@ @php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp