Fixed consume amount calculation when consuming multiple substituted subproducts at once and when multiple/different conversion factors were involved (fixes #2076)

This commit is contained in:
Bernd Bestel 2022-12-21 21:00:49 +01:00
parent 407344e86a
commit dd409b4bf9
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 9 additions and 1 deletions

View File

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

View File

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