diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index 45e72a1a..49d0aa8b 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -10,6 +10,7 @@ - Quantity unit conversions now support transitive conversions, means the QU hierarchy has now unlimited levels (thanks a lot @esclear) - Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work +- Fixed that the consumed amount was wrong, when consuming multiple substituted subproducts at once and when multiple/different conversion factors were involved ### Shopping list diff --git a/services/StockService.php b/services/StockService.php index 85f57803..508068c6 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -407,7 +407,7 @@ class StockService extends BaseService } $productStockAmount = floatval($productDetails->stock_amount_aggregated); - if ($amount > $productStockAmount) + if (round($amount, 2) > round($productStockAmount, 2)) { throw new \Exception('Amount to be consumed cannot be > current stock amount (if supplied, at the desired location)'); } @@ -460,6 +460,13 @@ class StockService extends BaseService $stockEntry->delete(); $amount -= $stockEntry->amount; + + if ($allowSubproductSubstitution && $stockEntry->product_id != $productId && $conversion != null) + { + // A sub product with QU conversions was used + // => Convert the rest amount back to be based on the original (parent) product for the next round + $amount = $amount / floatval($conversion->factor); + } } else {