Fix error message

This commit is contained in:
Laurent Destailleur 2022-06-28 20:11:18 +02:00
parent b0e0ceb8f6
commit 67ade177c7
3 changed files with 12 additions and 2 deletions

View File

@ -168,10 +168,13 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount) {
$object->labelshort = GETPOST('labelshort', 'alpha');
$result = $object->update($user);
if ($result > 0) {
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"] . "?id=" . $id);
header("Location: " . $urltogo);
exit();
} elseif ($result == -2) {
setEventMessages($langs->trans("ErrorAccountNumberAlreadyExists", $object->account_number), null, 'errors');
} else {
setEventMessages($object->error, null, 'errors');
}

View File

@ -347,8 +347,8 @@ class AccountingAccount extends CommonObject
/**
* Update record
*
* @param User $user Use making update
* @return int <0 if KO, >0 if OK
* @param User $user User making update
* @return int <0 if KO (-2 = duplicate), >0 if OK
*/
public function update($user)
{
@ -378,6 +378,12 @@ class AccountingAccount extends CommonObject
$this->db->commit();
return 1;
} else {
if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -2;
}
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;

View File

@ -427,6 +427,7 @@ SorryThisModuleIsNotCompatibleWithTheExperimentalFeatureOfSituationInvoices=Sorr
AccountancyErrorMismatchLetterCode=Mismatch in reconcile code
AccountancyErrorMismatchBalanceAmount=The balance (%s) is not equal to 0
AccountancyErrorLetteringBookkeeping=Errors have occurred concerning the transactions: %s
ErrorAccountNumberAlreadyExists=The accounting number %s already exists
## Import
ImportAccountingEntries=Accounting entries