diff --git a/changelog/58_UNRELEASED_2020-xx-xx.md b/changelog/58_UNRELEASED_2020-xx-xx.md index 9b7fe375..ae4b3779 100644 --- a/changelog/58_UNRELEASED_2020-xx-xx.md +++ b/changelog/58_UNRELEASED_2020-xx-xx.md @@ -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 diff --git a/services/StockService.php b/services/StockService.php index d19e578b..273b790c 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -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();