diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 05e508036ca..9a8dd9d1c1c 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3633,7 +3633,7 @@ class Facture extends CommonInvoice global $mysoc, $conf, $langs; - dol_syslog(get_class($this)."::addline id=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type, fk_unit=$fk_unit", LOG_DEBUG); + dol_syslog(get_class($this)."::addline id=$this->id, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product, remise_percent=$remise_percent, date_start=$date_start, date_end=$date_end, ventil=$ventil, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, type=$type, fk_unit=$fk_unit, desc=".dol_trunc($desc, 25), LOG_DEBUG); if ($this->statut == self::STATUS_DRAFT) { include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a1906123f62..c21dbe2f631 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4325,7 +4325,7 @@ abstract class CommonObject * @param int $status Status to set * @param int $elementId Id of element to force (use this->id by default if null) * @param string $elementType Type of element to force (use this->table_element by default) - * @param string $trigkey Trigger key to use for trigger. Use '' means automatic but it not recommended and is deprecated. + * @param string $trigkey Trigger key to use for trigger. Use '' means automatic but it is not recommended and is deprecated. * @param string $fieldstatus Name of status field in this->table_element * @return int <0 if KO, >0 if OK */ @@ -4375,41 +4375,49 @@ abstract class CommonObject if ($status == 1 && in_array($elementTable, array('inventory'))) { $sql .= ", date_validation = '".$this->db->idate(dol_now())."'"; } - $sql .= " WHERE rowid=".((int) $elementId); + $sql .= " WHERE rowid = ".((int) $elementId); + $sql .= " AND ".$fieldstatus." <> ".((int) $status); // We avoid update if status already correct dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); - if ($this->db->query($sql)) { + $resql = $this->db->query($sql); + if ($resql) { $error = 0; - // Try autoset of trigkey - if (empty($trigkey)) { - if ($this->element == 'supplier_proposal' && $status == 2) { - $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class - } - if ($this->element == 'supplier_proposal' && $status == 3) { - $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class - } - if ($this->element == 'supplier_proposal' && $status == 4) { - $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class - } - if ($this->element == 'fichinter' && $status == 3) { - $trigkey = 'FICHINTER_CLASSIFY_DONE'; - } - if ($this->element == 'fichinter' && $status == 2) { - $trigkey = 'FICHINTER_CLASSIFY_BILLED'; - } - if ($this->element == 'fichinter' && $status == 1) { - $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; - } - } + $nb_rows_affected = $this->db->affected_rows($resql); // should be 1 or 0 if status was already correct - if ($trigkey) { - // Call trigger - $result = $this->call_trigger($trigkey, $user); - if ($result < 0) { - $error++; + if ($nb_rows_affected >= 0) { + if (empty($trigkey)) { + // Try to guess trigkey (for backward compatibility, now we should have trigkey defined into the call of setStatus) + if ($this->element == 'supplier_proposal' && $status == 2) { + $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class + } + if ($this->element == 'supplier_proposal' && $status == 3) { + $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class + } + if ($this->element == 'supplier_proposal' && $status == 4) { + $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class + } + if ($this->element == 'fichinter' && $status == 3) { + $trigkey = 'FICHINTER_CLASSIFY_DONE'; + } + if ($this->element == 'fichinter' && $status == 2) { + $trigkey = 'FICHINTER_CLASSIFY_BILLED'; + } + if ($this->element == 'fichinter' && $status == 1) { + $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; + } } - // End call triggers + + if ($trigkey) { + // Call trigger + $result = $this->call_trigger($trigkey, $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + } else { + // The status was probably already good. We do nothing more, no triggers. } if (!$error) { diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 4988be3cefd..10bbefde7e5 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -180,7 +180,7 @@ function delivery_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref); + $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($tmpobject->ref); $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); $nbLinks = Link::count($db, $tmpobject->element, $tmpobject->id); $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$tmpobject->id; diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 975c071a07f..39a1886c45f 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -363,9 +363,9 @@ if ($action == 'create') { } $morehtmlref .= ''; - $morehtmlright = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'

'; + $morehtmlstatus = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'

'; - dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlright); + dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus); print '
'; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 22d1d0c7b19..5e220995cc7 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2152,8 +2152,9 @@ class Expedition extends CommonObject } } if ($shipments_match_order) { - dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for shipments with status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order'); - $order->cloture($user); + dol_syslog("Qty for the ".count($order->lines)." lines of the origin order is same than qty for lines in the shipment we close (shipments_match_order is true), with new status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order'); + // We close the order + $order->cloture($user); // Note this may also create an invoice if module workflow ask it } }