From c6a071622add08617bb20d108c749ccebabe1768 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 1 Dec 2021 15:26:40 +0100 Subject: [PATCH] Avoid a useless select --- htdocs/compta/facture/class/facture.class.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 649b7b0c093..686f714827a 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -463,11 +463,17 @@ class Facture extends CommonInvoice $this->status = self::STATUS_DRAFT; $this->statut = self::STATUS_DRAFT; - // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate) - if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) { - list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); + if (!empty($this->multicurrency_code)) { + // Multicurrency (test on $this->multicurrency_tx because we should take the default rate of multicurrency_code only if not using original rate) + if (empty($this->multicurrency_tx)) { + // If original rate is not set, we take a default value from date + list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); + } else { + // original rate multicurrency_tx and multicurrency_code are set, we use them + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } } else { - $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + $this->fk_multicurrency = 0; } if (empty($this->fk_multicurrency)) { $this->multicurrency_code = $conf->currency;