mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 18:34:32 +02:00
Added some tests for important entity methods.
This commit is contained in:
parent
0663a00df8
commit
89258bc102
18 changed files with 480 additions and 160 deletions
|
@ -116,7 +116,6 @@ class PartLot extends DBElement
|
|||
* Check if the current part lot is expired.
|
||||
* This is the case, if the expiration date is greater the the current date.
|
||||
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function isExpired(): ?bool
|
||||
{
|
||||
|
@ -125,7 +124,7 @@ class PartLot extends DBElement
|
|||
}
|
||||
|
||||
//Check if the expiration date is bigger then current time
|
||||
return $this->expiration_date < new \DateTime();
|
||||
return $this->expiration_date < new \DateTime('now');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ use Doctrine\Common\Collections\Collection;
|
|||
trait InstockTrait
|
||||
{
|
||||
/**
|
||||
* @var ?PartLot[]|Collection A list of part lots where this part is stored
|
||||
* @var Collection|PartLot[] A list of part lots where this part is stored
|
||||
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @Assert\Valid()
|
||||
* @ColumnSecurity(type="collection", prefix="lots")
|
||||
|
@ -146,6 +146,7 @@ trait InstockTrait
|
|||
|
||||
/**
|
||||
* Returns the summed amount of this part (over all part lots)
|
||||
* Part Lots that have unknown value or are expired, are not used for this value
|
||||
* @return float The amount of parts given in partUnit
|
||||
*/
|
||||
public function getAmountSum() : float
|
||||
|
@ -154,7 +155,7 @@ trait InstockTrait
|
|||
$sum = 0;
|
||||
foreach ($this->getPartLots() as $lot) {
|
||||
//Dont use the instock value, if it is unkown
|
||||
if ($lot->isInstockUnknown()) {
|
||||
if ($lot->isInstockUnknown() || $lot->isExpired() ?? false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue