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
- + diff --git a/views/productform.blade.php b/views/productform.blade.php index 8b74dd29..097ec69b 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -88,6 +88,15 @@ @endif + @if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) + @include('components.shoppinglocationpicker', array( + 'label' => 'Default store', + 'shoppinglocations' => $shoppinglocations + )) + @else + + @endif + @php if($mode == 'edit') { $value = $product->min_stock_amount; } else { $value = 0; } @endphp @include('components.numberpicker', array( 'id' => 'min_stock_amount', diff --git a/views/purchase.blade.php b/views/purchase.blade.php index f8e38489..aa753772 100644 --- a/views/purchase.blade.php +++ b/views/purchase.blade.php @@ -87,7 +87,8 @@
@include('components.shoppinglocationpicker', array( - 'shoppinglocations' => $shoppinglocations, + 'label' => 'Store', + 'shoppinglocations' => $shoppinglocations )) @else diff --git a/views/stockentryform.blade.php b/views/stockentryform.blade.php index 97f372e3..9b6035f3 100644 --- a/views/stockentryform.blade.php +++ b/views/stockentryform.blade.php @@ -67,6 +67,7 @@ 'isRequired' => false )) @include('components.shoppinglocationpicker', array( + 'label' => 'Store', 'shoppinglocations' => $shoppinglocations, 'prefillById' => $stockEntry->shopping_location_id ))