Fixed that product-opened-actions had no transaction_id in stock_log (fixes #732)

This commit is contained in:
Bernd Bestel 2020-04-13 17:04:59 +02:00
parent 7d9bad58b5
commit 1686fcca8e
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 11 additions and 3 deletions

View File

@ -17,6 +17,7 @@
- Fixed that "Default best before days" and "Default best before days after opened" on the product edit page were always shown regardless of the feature flags `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` and `FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING`
- Fixed that the form validation limits for the amount input and products with enabled tare weight handling were wrong
- Fixed that the price was saved wrong for products with a different purchase/stock quantity unit when using "Total price" on purchase (resulted for example in wrong recipe costs)
- Fixed that undoing "product-opened"-actions was not possible
### Shopping list fixes
- Fixed that the "shopping list to stock workflow"-dialog was not visible in compact view

View File

@ -724,7 +724,7 @@ class StockService extends BaseService
return null;
}
public function OpenProduct(int $productId, float $amount, $specificStockEntryId = 'default')
public function OpenProduct(int $productId, float $amount, $specificStockEntryId = 'default', &$transactionId = null)
{
if (!$this->ProductExists($productId))
{
@ -745,6 +745,11 @@ class StockService extends BaseService
$potentialStockEntries = FindAllObjectsInArrayByPropertyValue($potentialStockEntries, 'stock_id', $specificStockEntryId);
}
if ($transactionId === null)
{
$transactionId = uniqid();
}
foreach ($potentialStockEntries as $stockEntry)
{
if ($amount == 0)
@ -768,7 +773,8 @@ class StockService extends BaseService
'stock_id' => $stockEntry->stock_id,
'transaction_type' => self::TRANSACTION_TYPE_PRODUCT_OPENED,
'price' => $stockEntry->price,
'opened_date' => date('Y-m-d')
'opened_date' => date('Y-m-d'),
'transaction_id' => $transactionId
));
$logRow->save();
@ -802,7 +808,8 @@ class StockService extends BaseService
'stock_id' => $stockEntry->stock_id,
'transaction_type' => self::TRANSACTION_TYPE_PRODUCT_OPENED,
'price' => $stockEntry->price,
'opened_date' => date('Y-m-d')
'opened_date' => date('Y-m-d'),
'transaction_id' => $transactionId
));
$logRow->save();