From d9b8abe3e4080b17732ecccb614d9dceece657d1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 25 Nov 2025 14:20:05 +0100 Subject: [PATCH] FIX #36310 Accountancy - Data - Wrong account labels (cache) on write bookkeeping action (#36410) * FIX #36310 Accountancy - Data - Wrong account labels (cache) on writebookkeeping action (#36379) * Fix --- .../journal/expensereportsjournal.php | 20 ++++++++++++++----- .../accountancy/journal/purchasesjournal.php | 9 ++++++++- htdocs/accountancy/journal/sellsjournal.php | 18 +++++++++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 34abad53a40..2e62bdacc29 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -321,6 +321,16 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b if (!$errorforline) { foreach ($tabht[$key] as $k => $mt) { if ($mt) { + if (empty($conf->cache['accountingaccountincurrententity'][$k])) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $k, true); + $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount; + } else { + $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k]; + } + + $account_label = $accountingaccount->label; + // get compte id and label if ($accountingaccount->fetch(null, $k, true)) { $bookkeeping = new BookKeeping($db); @@ -335,9 +345,9 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = $accountingaccount->label; + $bookkeeping->label_compte = $account_label; - $bookkeeping->label_operation = $accountingaccount->label; + $bookkeeping->label_operation = $account_label; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; @@ -383,12 +393,12 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b foreach ($arrayofvat[$key] as $k => $mt) { if ($mt) { - if (empty($conf->cache['accountingaccountincurrententity'][$k])) { + if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch(0, $k, true); - $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount; + $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount; } else { - $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k]; + $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k]; } $account_label = $accountingaccount->label; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 91ac6b97ad8..324d45c62bb 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -616,7 +616,14 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b foreach ($arrayofvat[$key] as $k => $mt) { if ($mt) { - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label + if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $k, true); + $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount; + } else { + $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k]; + } + $label_account = $accountingaccount->label; $bookkeeping = new BookKeeping($db); diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index d46d7e8ff31..b7da60a23af 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -679,7 +679,14 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b foreach ($arrayofvat[$key] as $k => $mt) { if ($mt) { - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label + if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $k, true); + $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount; + } else { + $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k]; + } + $label_account = $accountingaccount->label; $bookkeeping = new BookKeeping($db); @@ -740,7 +747,14 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) { foreach ($tabrevenuestamp[$key] as $k => $mt) { if ($mt) { - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label + if (empty($conf->cache['accountingaccountincurrententity_rs'][$k])) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $k, true); + $conf->cache['accountingaccountincurrententity_rs'][$k] = $accountingaccount; + } else { + $accountingaccount = $conf->cache['accountingaccountincurrententity_rs'][$k]; + } + $label_account = $accountingaccount->label; $bookkeeping = new BookKeeping($db);