mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 20:26:42 +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:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
- Quantity unit conversions now support transitive conversions, means the QU hierarchy has now unlimited levels (thanks a lot @esclear)
|
- 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 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
|
### Shopping list
|
||||||
|
|
||||||
|
@@ -407,7 +407,7 @@ class StockService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$productStockAmount = floatval($productDetails->stock_amount_aggregated);
|
$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)');
|
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();
|
$stockEntry->delete();
|
||||||
|
|
||||||
$amount -= $stockEntry->amount;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user