mirror of
https://github.com/grocy/grocy.git
synced 2025-09-16 09:51:30 +00:00
Reviewed latest changes regarding price handling views
This commit is contained in:
@@ -90,4 +90,6 @@
|
||||
|
||||
- Added a new endpoint `GET /stock/locations/{locationId}/entries` to get all stock entries of a given location (similar to the already existing endpoint `GET /stock/products/{productId}/entries`)
|
||||
- Endpoint `/recipes/{recipeId}/consume`: Fixed that consuming partially fulfilled recipes was possible, although an error was already returned in that case (and potentially some of the in-stock ingredients were consumed in fact)
|
||||
- Endpoint `/stock/products/{productId}`: The property/field `oldest_price` has been removed (as this had no real sense)
|
||||
- Endpoint `/stock/products/{productId}`:
|
||||
- New field/property `current_price` which returns the current price of the corresponding products based on the stock entry to use next defined by the default consume rule (Opened first, then first due first, then first in first out)
|
||||
- The field/property `oldest_price` is deprecated and will be removed in a future version (this had no real sense, currently returns the same as `current_price`)
|
||||
|
@@ -4751,10 +4751,21 @@
|
||||
"format": "date-time"
|
||||
},
|
||||
"last_price": {
|
||||
"type": "number"
|
||||
"type": "number",
|
||||
"description": "The price of the last purchase of the corresponding product"
|
||||
},
|
||||
"avg_price": {
|
||||
"type": "number"
|
||||
"type": "number",
|
||||
"description": "The average price af all items currently in stock of the corresponding product"
|
||||
},
|
||||
"current_price": {
|
||||
"type": "number",
|
||||
"description": "The current price of the corresponding products, based on the stock entry to use next defined by the default consume rule (Opened first, then first due first, then first in first out)"
|
||||
},
|
||||
"oldest_price": {
|
||||
"type": "number",
|
||||
"description": "This field is deprecated and will be removed in a future version (currently returns the same as `current_price`)",
|
||||
"deprecated": true
|
||||
},
|
||||
"last_shopping_location_id": {
|
||||
"type": "integer"
|
||||
@@ -4826,6 +4837,7 @@
|
||||
},
|
||||
"last_price": null,
|
||||
"avg_price": null,
|
||||
"current_price": null,
|
||||
"last_shopping_location_id": null,
|
||||
"next_due_date": "2019-07-07",
|
||||
"location": {
|
||||
|
@@ -6,12 +6,12 @@ AS
|
||||
Opened first, then first due first, then first in first out
|
||||
|
||||
This orders the stock entries by that
|
||||
=> Lowest "priority" per product = the stock entry to use next
|
||||
=> Highest "priority" per product = the stock entry to use next
|
||||
*/
|
||||
|
||||
SELECT
|
||||
-1, -- Dummy
|
||||
ROW_NUMBER() OVER(PARTITION BY product_id ORDER BY open DESC, best_before_date ASC, purchased_date ASC) AS priority,
|
||||
-1 AS id, -- Dummy
|
||||
(ROW_NUMBER() OVER(PARTITION BY product_id ORDER BY open DESC, best_before_date ASC, purchased_date ASC)) * -1 AS priority,
|
||||
product_id,
|
||||
stock_id,
|
||||
price
|
||||
@@ -27,14 +27,14 @@ AS
|
||||
*/
|
||||
|
||||
SELECT
|
||||
-1, -- Dummy,
|
||||
-1 AS id, -- Dummy,
|
||||
p.id AS product_id,
|
||||
IFNULL(snu.price, plp.price) AS price
|
||||
FROM products p
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
product_id,
|
||||
MIN(priority),
|
||||
MAX(priority),
|
||||
price -- Bare column, ref https://www.sqlite.org/lang_select.html#bare_columns_in_an_aggregate_query
|
||||
FROM stock_next_use
|
||||
GROUP BY product_id
|
||||
|
@@ -716,7 +716,7 @@ class StockService extends BaseService
|
||||
$quStock = $this->getDatabase()->quantity_units($product->qu_id_stock);
|
||||
$location = $this->getDatabase()->locations($product->location_id);
|
||||
$averageShelfLifeDays = intval($this->getDatabase()->stock_average_product_shelf_life()->where('id', $productId)->fetch()->average_shelf_life_days);
|
||||
$defaultShoppingLocation = null;
|
||||
$currentPrice = $this->getDatabase()->products_current_price()->where('product_id', $productId)->fetch()->price;
|
||||
|
||||
$consumeCount = $this->getDatabase()->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone = 0')->sum('amount') * -1;
|
||||
$consumeCountSpoiled = $this->getDatabase()->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone = 0 AND spoiled = 1')->sum('amount') * -1;
|
||||
@@ -740,6 +740,8 @@ class StockService extends BaseService
|
||||
'quantity_unit_stock' => $quStock,
|
||||
'last_price' => $lastPrice,
|
||||
'avg_price' => $avgPrice,
|
||||
'oldest_price' => $currentPrice, // Deprecated
|
||||
'current_price' => $currentPrice,
|
||||
'last_shopping_location_id' => $lastShoppingLocation,
|
||||
'default_shopping_location_id' => $product->shopping_location_id,
|
||||
'next_due_date' => $nextDueDate,
|
||||
|
Reference in New Issue
Block a user