mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-06-26 20:41:41 +00:00
Warn if ProjectBuild passed lot if null
Fixed caused deprecations for it
This commit is contained in:
parent
fe0809230b
commit
b8fc5d4ace
2 changed files with 20 additions and 7 deletions
|
|
@ -84,8 +84,10 @@ final class ProjectBuildRequest
|
||||||
$remaining_amount = $this->getNeededAmountForBOMEntry($bom_entry);
|
$remaining_amount = $this->getNeededAmountForBOMEntry($bom_entry);
|
||||||
foreach($this->getPartLotsForBOMEntry($bom_entry) as $lot) {
|
foreach($this->getPartLotsForBOMEntry($bom_entry) as $lot) {
|
||||||
//If the lot has instock use it for the build
|
//If the lot has instock use it for the build
|
||||||
$this->withdraw_amounts[$lot->getID()] = min($remaining_amount, $lot->getAmount());
|
$id = $lot->getID() ?? throw new \RuntimeException("Part lot needs to have an ID!");
|
||||||
$remaining_amount -= max(0, $this->withdraw_amounts[$lot->getID()]);
|
|
||||||
|
$this->withdraw_amounts[$id] = min($remaining_amount, $lot->getAmount());
|
||||||
|
$remaining_amount -= max(0, $this->withdraw_amounts[$id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +178,10 @@ final class ProjectBuildRequest
|
||||||
{
|
{
|
||||||
$lot_id = $lot instanceof PartLot ? $lot->getID() : $lot;
|
$lot_id = $lot instanceof PartLot ? $lot->getID() : $lot;
|
||||||
|
|
||||||
|
if ($lot_id === null) {
|
||||||
|
throw new \InvalidArgumentException('The given lot must have an ID!');
|
||||||
|
}
|
||||||
|
|
||||||
if (! array_key_exists($lot_id, $this->withdraw_amounts)) {
|
if (! array_key_exists($lot_id, $this->withdraw_amounts)) {
|
||||||
throw new \InvalidArgumentException('The given lot is not in the withdraw amounts array!');
|
throw new \InvalidArgumentException('The given lot is not in the withdraw amounts array!');
|
||||||
}
|
}
|
||||||
|
|
@ -192,10 +198,12 @@ final class ProjectBuildRequest
|
||||||
{
|
{
|
||||||
if ($lot instanceof PartLot) {
|
if ($lot instanceof PartLot) {
|
||||||
$lot_id = $lot->getID();
|
$lot_id = $lot->getID();
|
||||||
} elseif (is_int($lot)) {
|
|
||||||
$lot_id = $lot;
|
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('The given lot must be an instance of PartLot or an ID of a PartLot!');
|
$lot_id = $lot;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($lot_id === null) {
|
||||||
|
throw new \InvalidArgumentException('The given lot must have an ID!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->withdraw_amounts[$lot_id] = $amount;
|
$this->withdraw_amounts[$lot_id] = $amount;
|
||||||
|
|
@ -296,7 +304,7 @@ final class ProjectBuildRequest
|
||||||
* @param bool $dont_check_quantity
|
* @param bool $dont_check_quantity
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setDontCheckQuantity(bool $dont_check_quantity): ProjectBuildRequest
|
public function setDontCheckQuantity(bool $dont_check_quantity): self
|
||||||
{
|
{
|
||||||
$this->dont_check_quantity = $dont_check_quantity;
|
$this->dont_check_quantity = $dont_check_quantity;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,12 @@ final class ProjectBuildRequestTest extends TestCase
|
||||||
|
|
||||||
$part2->setName('Part 2');
|
$part2->setName('Part 2');
|
||||||
$part2->setPartUnit($float_unit);
|
$part2->setPartUnit($float_unit);
|
||||||
$this->lot2 = new PartLot();
|
$this->lot2 = new class extends PartLot {
|
||||||
|
public function getID(): ?int
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
};;
|
||||||
$part2->addPartLot($this->lot2);
|
$part2->addPartLot($this->lot2);
|
||||||
$this->lot2->setAmount(2.5);
|
$this->lot2->setAmount(2.5);
|
||||||
$this->lot2->setDescription('Lot 2');
|
$this->lot2->setDescription('Lot 2');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue