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
This commit is contained in:
Alexandre SPANGARO 2025-11-25 14:20:05 +01:00 committed by GitHub
parent 7f27552a95
commit d9b8abe3e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 8 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);