mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 11:48:49 +02:00
Allow to set the exchange rate of a currency to null (not existing) after it was set once
This commit is contained in:
parent
2d5f23271f
commit
e7a1b33ae6
1 changed files with 6 additions and 3 deletions
|
@ -157,12 +157,15 @@ class Currency extends AbstractStructuralDBElement
|
|||
*/
|
||||
public function setExchangeRate(?BigDecimal $exchange_rate): self
|
||||
{
|
||||
if (!$exchange_rate instanceof BigDecimal) {
|
||||
//If the exchange rate is null, set it to null and return.
|
||||
if ($exchange_rate === null) {
|
||||
$this->exchange_rate = null;
|
||||
return $this;
|
||||
}
|
||||
$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) {
|
||||
//Or if the current exchange rate is currently null, as we can not compare it then
|
||||
if ($this->exchange_rate === null || $exchange_rate->compareTo($this->exchange_rate) !== 0) {
|
||||
$this->exchange_rate = $exchange_rate;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue