Fixed wrongly detected changes of prices caused by not identical objects.

This commit is contained in:
Jan Böhmer 2020-05-20 22:45:41 +02:00
parent f92802a3c7
commit c60f27ef86
3 changed files with 23 additions and 3 deletions

View file

@ -159,7 +159,15 @@ class Supplier extends AbstractCompany
*/ */
public function setShippingCosts(?BigDecimal $shipping_costs): self public function setShippingCosts(?BigDecimal $shipping_costs): self
{ {
if ($shipping_costs === null) {
$this->shipping_costs = null;
}
//Only change the object, if the value changes, so that doctrine does not detect it as changed.
if ((string) $shipping_costs !== (string) $this->shipping_costs) {
$this->shipping_costs = $shipping_costs; $this->shipping_costs = $shipping_costs;
}
return $this; return $this;
} }
} }

View file

@ -51,6 +51,7 @@ use Brick\Math\RoundingMode;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use DoctrineExtensions\Query\Mysql\Round;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -181,7 +182,14 @@ class Currency extends AbstractStructuralDBElement
*/ */
public function setExchangeRate(?BigDecimal $exchange_rate): self public function setExchangeRate(?BigDecimal $exchange_rate): self
{ {
if ($exchange_rate === null) {
$this->exchange_rate = null;
}
$tmp = $exchange_rate->toScale(self::PRICE_SCALE, RoundingMode::HALF_UP);
//Only change the object, if the value changes, so that doctrine does not detect it as changed.
if ((string) $tmp !== (string) $this->exchange_rate) {
$this->exchange_rate = $exchange_rate; $this->exchange_rate = $exchange_rate;
}
return $this; return $this;
} }

View file

@ -275,7 +275,11 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
*/ */
public function setPrice(BigDecimal $new_price): self public function setPrice(BigDecimal $new_price): self
{ {
$this->price = $new_price->toScale(self::PRICE_PRECISION, RoundingMode::HALF_UP); $tmp = $new_price->toScale(self::PRICE_PRECISION, RoundingMode::HALF_UP);
//Only change the object, if the value changes, so that doctrine does not detect it as changed.
if ((string) $tmp !== (string) $this->price) {
$this->price = $tmp;
}
return $this; return $this;
} }