mirror of
https://github.com/grocy/grocy.git
synced 2025-08-28 17:10:11 +00:00
Fixed self production amount was wrong for tare weight handling enabled products (fixes #1431)
This commit is contained in:
@@ -66,7 +66,7 @@ class RecipesService extends BaseService
|
||||
if (!empty($recipeRow->product_id))
|
||||
{
|
||||
$recipeResolvedRow = $this->getDatabase()->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch();
|
||||
$this->getStockService()->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs));
|
||||
$this->getStockService()->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs), null, null, $dummyTransactionId, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -113,7 +113,7 @@ class StockService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = 0)
|
||||
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = 0, $addExactAmount = false)
|
||||
{
|
||||
if (!$this->ProductExists($productId))
|
||||
{
|
||||
@@ -127,6 +127,11 @@ class StockService extends BaseService
|
||||
// The amount to be posted needs to be the given amount - stock amount - tare weight
|
||||
if ($productDetails->product->enable_tare_weight_handling == 1)
|
||||
{
|
||||
if ($addExactAmount)
|
||||
{
|
||||
$amount = floatval($productDetails->stock_amount) + floatval($productDetails->product->tare_weight) + $amount;
|
||||
}
|
||||
|
||||
if ($amount <= floatval($productDetails->product->tare_weight) + floatval($productDetails->stock_amount))
|
||||
{
|
||||
throw new \Exception('The amount cannot be lower or equal than the defined tare weight + current stock amount');
|
||||
|
Reference in New Issue
Block a user