From 2df791ccf7b4c70f6ebbd1e79dd0ee67e5a16169 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Oct 2022 21:22:17 +0200 Subject: [PATCH 1/3] Fix badge not visible on delivery tab --- htdocs/core/lib/sendings.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index e2ab74b8cfc..c5ae3c3d2ef 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; From 035448c66e61f04bb194ff45171fa3e1da18dcfb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Oct 2022 21:36:30 +0200 Subject: [PATCH 2/3] Fix log cleaner --- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/delivery/card.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7404f2595e2..8f665831549 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3265,7 +3265,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/delivery/card.php b/htdocs/delivery/card.php index 8082c654a55..23e9b1043b3 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -360,9 +360,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 '
'; From 4e4b0e0039fedf52b86ab9a186a344ff4c67cae0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Oct 2022 22:44:20 +0200 Subject: [PATCH 3/3] FIX Duplicate creation of invoice when closing shipment linked to order --- htdocs/core/class/commonobject.class.php | 68 +++++++++++--------- htdocs/expedition/class/expedition.class.php | 7 +- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b9b09450642..714320fbf1c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4160,7 +4160,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 */ @@ -4210,41 +4210,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/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index a29919b7346..8cf91601073 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2167,7 +2167,7 @@ class Expedition extends CommonObject $this->db->begin(); - $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut='.self::STATUS_CLOSED; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut = '.self::STATUS_CLOSED; $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut > 0'; $resql = $this->db->query($sql); @@ -2191,8 +2191,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 } }