From 6018fd4eeea7c84adf91889305ce95fc5aab5349 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 5 Jun 2026 09:04:24 +0200 Subject: [PATCH 1/4] FIX Accountancy - Closure - Income and deficit accounts should not prevent the closing process if they contain data --- .../accountancy/class/bookkeeping.class.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 1778bf429f4..7be24465074 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -352,6 +352,16 @@ class BookKeeping extends CommonObject } $sql .= " AND entity = ".$conf->entity; // Do not use getEntity for accounting features + // Allow duplicates in incomes or loss statements + $accountProfit = getDolGlobalString('ACCOUNTING_RESULT_PROFIT'); + $accountLoss = getDolGlobalString('ACCOUNTING_RESULT_LOSS'); + + if (($accountProfit && $this->numero_compte === trim($accountProfit)) || + ($accountLoss && $this->numero_compte === trim($accountLoss))) { + // If the account being processed corresponds to the “Profit” or “Loss” constant, the detection is bypassed + $sql .= " AND 1 = 2"; + } + $resql = $this->db->query($sql); if ($resql) { @@ -477,7 +487,18 @@ class BookKeeping extends CommonObject $result = -3; $error++; $this->error = 'BookkeepingRecordAlreadyExists'; - dol_syslog(__METHOD__.' '.$this->error, LOG_WARNING); + $this->errors[] = $langs->trans('WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet); + + dol_syslog(__METHOD__ . ' duplicate record detected: ' + . 'doc_type=' . $this->doc_type + . ', doc_ref=' . $this->doc_ref + . ', fk_doc=' . ((int) $this->fk_doc) + . ', fk_docdet=' . ((int) $this->fk_docdet) + . ', numero_compte=' . $this->numero_compte + . ', label_operation=' . $this->label_operation + . ', subledger_account=' . ($this->subledger_account ?? '(null)'), + LOG_WARNING + ); } } else { $result = -5; From f6efa0d8e45f576bca8d22f7fcc9335212ab2533 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 5 Jun 2026 11:21:03 +0200 Subject: [PATCH 2/4] CI --- htdocs/accountancy/class/bookkeeping.class.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 7be24465074..8b5a3411979 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -489,16 +489,7 @@ class BookKeeping extends CommonObject $this->error = 'BookkeepingRecordAlreadyExists'; $this->errors[] = $langs->trans('WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet); - dol_syslog(__METHOD__ . ' duplicate record detected: ' - . 'doc_type=' . $this->doc_type - . ', doc_ref=' . $this->doc_ref - . ', fk_doc=' . ((int) $this->fk_doc) - . ', fk_docdet=' . ((int) $this->fk_docdet) - . ', numero_compte=' . $this->numero_compte - . ', label_operation=' . $this->label_operation - . ', subledger_account=' . ($this->subledger_account ?? '(null)'), - LOG_WARNING - ); + dol_syslog(__METHOD__ . ' duplicate record detected: doc_type={$this->doc_type}, doc_ref={$this->doc_ref}, fk_doc={(int) $this->fk_doc}, fk_docdet={(int) $this->fk_docdet}', LOG_WARNING); } } else { $result = -5; From 36e0fd5b501389e644849bdbb998c3b845c94a07 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 5 Jun 2026 11:28:14 +0200 Subject: [PATCH 3/4] CI --- htdocs/accountancy/class/bookkeeping.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 8b5a3411979..95028b0a071 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -489,7 +489,7 @@ class BookKeeping extends CommonObject $this->error = 'BookkeepingRecordAlreadyExists'; $this->errors[] = $langs->trans('WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet); - dol_syslog(__METHOD__ . ' duplicate record detected: doc_type={$this->doc_type}, doc_ref={$this->doc_ref}, fk_doc={(int) $this->fk_doc}, fk_docdet={(int) $this->fk_docdet}', LOG_WARNING); + dol_syslog(get_class($this).":: duplicate record detected: doc_type=" . $this->doc_type.", doc_ref=" . $this->doc_ref . ", fk_doc=" . ((int) $this->fk_doc) . ", fk_docdet=" . ((int) $this->fk_docdet), LOG_WARNING); } } else { $result = -5; From 83e4e773cf9925c0de812869fcfa8451c285c996 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 5 Jun 2026 11:30:24 +0200 Subject: [PATCH 4/4] CI --- htdocs/accountancy/class/bookkeeping.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 95028b0a071..98ae7cc4b63 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -489,7 +489,7 @@ class BookKeeping extends CommonObject $this->error = 'BookkeepingRecordAlreadyExists'; $this->errors[] = $langs->trans('WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet); - dol_syslog(get_class($this).":: duplicate record detected: doc_type=" . $this->doc_type.", doc_ref=" . $this->doc_ref . ", fk_doc=" . ((int) $this->fk_doc) . ", fk_docdet=" . ((int) $this->fk_docdet), LOG_WARNING); + dol_syslog(get_class($this).":: create duplicate record detected: doc_type={$this->doc_type}, doc_ref={$this->doc_ref}, fk_doc={((int) $this->fk_doc)}, fk_docdet={((int) $this->fk_docdet)}", LOG_WARNING); } } else { $result = -5;