partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit e18d5e86ef5f4b2f4bbf0aa166860ef0b6f6002b
parent df503118a55841348fe76728a5fb928703dfe4a0
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 28 Nov 2015 16:39:51 +0100

Fixed average price calculation, related to #500

Diffstat:
Msrc/PartKeepr/PartBundle/Entity/Part.php | 20++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php @@ -139,6 +139,7 @@ class Part extends BaseEntity * The average price for the part. Note that this is a cached value. * * @ORM\Column(type="decimal",precision=13,scale=4,nullable=false) + * @Groups({"default"}) * @var float */ private $averagePrice = 0; @@ -636,10 +637,7 @@ class Part extends BaseEntity } /** - * Sets the average price for this unit - * - * @todo Is this actually used? - * + * Sets the average price for this part * @param float $price The price to set */ public function setAveragePrice($price) @@ -648,6 +646,15 @@ class Part extends BaseEntity } /** + * Returns the acrage price + * + * @return float + */ + public function getAveragePrice () { + return $this->averagePrice; + } + + /** * Sets the storage location for this part * * @param \PartKeepr\StorageLocationBundle\Entity\StorageLocation $storageLocation The storage location @@ -788,15 +795,16 @@ class Part extends BaseEntity $price = 0; foreach ($this->getStockLevels() as $stockLevel) { - $price += $stockLevel->getPrice(); if ($stockLevel->getStockLevel() < 0) { $this->setRemovals(true); + } else { + $price += $stockLevel->getPrice() * $stockLevel->getStockLevel(); } $sum += $stockLevel->getStockLevel(); } - $this->setAveragePrice($price); + $this->setAveragePrice($price / $sum); $this->setStockLevel($sum); if ($sum < $this->getMinStockLevel()) {