mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Fixed undoing a consume transaction of an opened item added it back to stock unopened (fixes #1191)
This commit is contained in:
parent
2e01ecbe58
commit
25f5f98b75
@ -82,6 +82,7 @@
|
||||
- Fixed that consuming (and editing the amount of) products with enabled tare weight handling did not work on the stock entries page
|
||||
- Fixed that the recipes dropdown on the consume page also displayed internal recipes (thanks @kriddles)
|
||||
- Fixed that opening tare weight handling enabled products is not possible via the UI and the API (as this makes no sense)
|
||||
- Fixed that undoing a consume transaction of an opened item added it back to stock unopened
|
||||
|
||||
### Shopping list improvements
|
||||
- Decimal amounts are now allowed (for any product, rounded by two decimal places)
|
||||
|
@ -1125,7 +1125,6 @@ class StockService extends BaseService
|
||||
public function UndoBooking($bookingId, $skipCorrelatedBookings = false)
|
||||
{
|
||||
$logRow = $this->getDatabase()->stock_log()->where('id = :1 AND undone = 0', $bookingId)->fetch();
|
||||
|
||||
if ($logRow == null)
|
||||
{
|
||||
throw new \Exception('Booking does not exist or was already undone');
|
||||
@ -1171,7 +1170,8 @@ class StockService extends BaseService
|
||||
'purchased_date' => $logRow->purchased_date,
|
||||
'stock_id' => $logRow->stock_id,
|
||||
'price' => $logRow->price,
|
||||
'opened_date' => $logRow->opened_date
|
||||
'opened_date' => $logRow->opened_date,
|
||||
'open' => $logRow->opened_date !== null
|
||||
]);
|
||||
$stockRow->save();
|
||||
|
||||
@ -1184,14 +1184,12 @@ class StockService extends BaseService
|
||||
elseif ($logRow->transaction_type === self::TRANSACTION_TYPE_TRANSFER_TO)
|
||||
{
|
||||
$stockRow = $this->getDatabase()->stock()->where('stock_id = :1 AND location_id = :2', $logRow->stock_id, $logRow->location_id)->fetch();
|
||||
|
||||
if ($stockRow === null)
|
||||
{
|
||||
throw new \Exception('Booking does not exist or was already undone');
|
||||
}
|
||||
|
||||
$newAmount = $stockRow->amount - $logRow->amount;
|
||||
|
||||
if ($newAmount == 0)
|
||||
{
|
||||
$stockRow->delete();
|
||||
@ -1212,10 +1210,8 @@ class StockService extends BaseService
|
||||
}
|
||||
elseif ($logRow->transaction_type === self::TRANSACTION_TYPE_TRANSFER_FROM)
|
||||
{
|
||||
// Add corresponding amount back to stock or
|
||||
// create a row if missing
|
||||
// Add corresponding amount back to stock
|
||||
$stockRow = $this->getDatabase()->stock()->where('stock_id = :1 AND location_id = :2', $logRow->stock_id, $logRow->location_id)->fetch();
|
||||
|
||||
if ($stockRow === null)
|
||||
{
|
||||
$stockRow = $this->getDatabase()->stock()->createRow([
|
||||
@ -1244,7 +1240,7 @@ class StockService extends BaseService
|
||||
}
|
||||
elseif ($logRow->transaction_type === self::TRANSACTION_TYPE_PRODUCT_OPENED)
|
||||
{
|
||||
// Remove opened flag from corresponding log entry
|
||||
// Remove opened flag from corresponding stock entry
|
||||
$stockRows = $this->getDatabase()->stock()->where('stock_id = :1 AND amount = :2 AND purchased_date = :3', $logRow->stock_id, $logRow->amount, $logRow->purchased_date)->limit(1);
|
||||
$stockRows->update([
|
||||
'open' => 0,
|
||||
@ -1277,7 +1273,6 @@ class StockService extends BaseService
|
||||
|
||||
$openedDate = $logRow->opened_date;
|
||||
$open = true;
|
||||
|
||||
if ($openedDate == null)
|
||||
{
|
||||
$open = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user