Handle edited stock entries in GetProductPriceHistory (fixes #913)

This commit is contained in:
Bernd Bestel 2020-08-25 19:09:47 +02:00
parent 0b98504371
commit 4058925f40
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 24 additions and 1 deletions

View File

@ -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

22
migrations/0110.sql Normal file
View File

@ -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')
);

View File

@ -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(