Add support for "Move on Open" (#1863)

* Add functionality to move a product when it is opened

* Update the API to support this (and some other new fields)

* Remove console, update move on open when either the default or the consume location change

* Fix conflict from fridge

* Ignore .DS_STORE from macOS

* Fix the migration conflict

* Fix the default location not appending properly

* Revert changes no longer needed

* Fix the checkbox disable logic, and call the function on page load

* Simplify the transfer to use the existing function (which also adds logs)

* Only move it if it's moving

* Code formatting / naming

* Clarify help text (it's not always about one unit, but about the corresponding amount opened)

* Handle splitted stock entries + optimized/unified product property checks

* Added UI feedback on auto moving

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
Rosemary Orchard
2022-04-18 17:25:08 +01:00
committed by GitHub
parent 0152f1c69d
commit 5e30e89737
10 changed files with 117 additions and 7 deletions

View File

@@ -734,6 +734,12 @@ class StockService extends BaseService
}
$spoilRate = ($consumeCountSpoiled * 100.0) / $consumeCount;
$defaultConsumeLocation = null;
if (!empty($product->default_consume_location_id))
{
$defaultConsumeLocation = $this->getDatabase()->locations($product->default_consume_location_id);
}
return [
'product' => $product,
'product_barcodes' => $productBarcodes,
@@ -758,6 +764,7 @@ class StockService extends BaseService
'spoil_rate_percent' => $spoilRate,
'is_aggregated_amount' => $stockCurrentRow->is_aggregated_amount,
'has_childs' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0,
'default_consume_location' => $defaultConsumeLocation
];
}
@@ -1057,6 +1064,15 @@ class StockService extends BaseService
$amount = 0;
}
if ($product->move_on_open == 1)
{
$locationIdTo = $product->default_consume_location_id;
if (!empty($locationIdTo) && $locationIdTo != $stockEntry->location_id)
{
$this->TransferProduct($stockEntry->product_id, $stockEntry->amount, $stockEntry->location_id, $locationIdTo, $stockEntry->stock_id, $transactionId);
}
}
}
return $transactionId;