Fix option WITHDRAWAL_WITHOUT_BIC

This commit is contained in:
Laurent Destailleur 2024-07-25 22:02:20 +02:00
parent 67c7e2fdce
commit 50190db5c7
2 changed files with 37 additions and 2 deletions

View File

@ -1627,7 +1627,9 @@ class Account extends CommonObject
$error++;
$this->error = 'IBANNotValid';
}
if (!checkSwiftForAccount($this) or !(empty($this->bic) && getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC'))) {
// Call function to check Swift/BIC.
// A non valid BIC/Swift is a problem if: it is not empty or always a problem if WITHDRAWAL_WITHOUT_BIC is not set).
if (!checkSwiftForAccount($this) && (!empty($this->bic) || !getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC'))) {
$error++;
$this->error = 'SwiftNotValid';
}

View File

@ -142,6 +142,39 @@ class BankAccountTest extends CommonClassTest
print __METHOD__." checkIbanForAccount(".$localobject2->iban.") = ".$result."\n";
$this->assertTrue($result);
return $localobject;
}
/**
* testCheckSwiftForAccount
*
* @param Account $localobject Account
* @return int
*
* @depends testBankAccountOther
* The depends says test is run only if previous is ok
*/
public function testCheckSwiftForAccount($localobject)
{
global $conf,$user,$langs,$db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
$localobject->bic = 'PSSTFRPPMARBIDON';
$result = checkSwiftForAccount($localobject);
print __METHOD__." checkSwiftForAccount ".$localobject->bic." = ".$result."\n";
$this->assertFalse($result);
$localobject->bic = 'PSSTFRPPMAR';
$result = checkSwiftForAccount($localobject);
print __METHOD__." checkSwiftForAccount ".$localobject->bic." = ".$result."\n";
$this->assertTrue($result);
return $localobject->id;
}
@ -151,7 +184,7 @@ class BankAccountTest extends CommonClassTest
* @param int $id Id of contract
* @return int
*
* @depends testBankAccountOther
* @depends testCheckSwiftForAccount
* The depends says test is run only if previous is ok
*/
public function testBankAccountDelete($id)