mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
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:
parent
407344e86a
commit
dd409b4bf9
@ -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
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user