diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index b70b733e..ed5a0f98 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -28,6 +28,7 @@ - Fixed that location & product groups filter on the stock overview page did a contains search instead an exact search - Fixed that the amount on the success popup was wrong when consuming a product with "Tare weight handling" enabled - Fixed that the aggregated amount of parent products was wrong on the stock overview page when the child products had not the same stock quantity units +- Fixed that edited stock entries were not considered for the price history chart on the product card ### Shopping list improvements diff --git a/migrations/0110.sql b/migrations/0110.sql new file mode 100644 index 00000000..5f0c7600 --- /dev/null +++ b/migrations/0110.sql @@ -0,0 +1,22 @@ +CREATE VIEW product_price_history +AS +SELECT + sl.product_id AS id, -- Dummy, LessQL needs an id column + sl.product_id, + sl.price, + sl.purchased_date, + sl.shopping_location_id +FROM stock_log sl +WHERE sl.transaction_type IN ('purchase', 'inventory-correction', 'stock-edit-new') + AND sl.undone = 0 + AND sl.price IS NOT NULL + AND sl.id NOT IN ( + -- These are edited purchase and inventory-correction rows + SELECT sl_origin.id + FROM stock_log sl_origin + JOIN stock_log sl_edit + ON sl_origin.stock_id = sl_edit.stock_id + AND sl_edit.transaction_type = 'stock-edit-new' + AND sl_edit.id > sl_origin.id + WHERE sl_origin.transaction_type IN ('purchase', 'inventory-correction') + ); diff --git a/services/StockService.php b/services/StockService.php index aba72d4d..ca2e7ca6 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -182,7 +182,7 @@ class StockService extends BaseService $returnData = array(); $shoppingLocations = $this->getDatabase()->shopping_locations(); - $rows = $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)->whereNOT('price', null)->orderBy('purchased_date', 'DESC'); + $rows = $this->getDatabase()->product_price_history()->where('product_id = :1', $productId)->orderBy('purchased_date', 'DESC'); foreach ($rows as $row) { $returnData[] = array(