mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #558 from acsone/12.0-ref_account_banking_pain_base_bic_constraint_tbi
[12.0] [REF] Account Banking Pain Base: constraint on BIC
This commit is contained in:
@@ -5,3 +5,4 @@ from . import account_payment_mode
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import account_payment_method
|
||||
from . import res_bank
|
||||
|
||||
33
account_banking_pain_base/models/res_bank.py
Normal file
33
account_banking_pain_base/models/res_bank.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import re
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
BIC_REGEX = re.compile(r"[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$")
|
||||
|
||||
|
||||
class ResBank(models.Model):
|
||||
_inherit = 'res.bank'
|
||||
|
||||
@api.multi
|
||||
@api.constrains('bic')
|
||||
def _check_bic(self):
|
||||
"""
|
||||
This method strengthens the constraint on the BIC of the bank account
|
||||
(The account_payment_order module already checks the length in the
|
||||
check_bic_length method).
|
||||
:raise: ValidationError if the BIC doesn't respect the regex of the
|
||||
SEPA pain schemas.
|
||||
"""
|
||||
invalid_banks = self.filtered(lambda r: not BIC_REGEX.match(r.bic))
|
||||
if invalid_banks:
|
||||
raise ValidationError(_(
|
||||
"The following Bank Identifier Codes (BIC) do not respect "
|
||||
"the SEPA pattern:\n{bic_list}\n\nSEPA pattern: "
|
||||
"{sepa_pattern}").format(
|
||||
sepa_pattern=BIC_REGEX.pattern,
|
||||
bic_list="\n".join(invalid_banks.mapped('bic'))
|
||||
))
|
||||
Reference in New Issue
Block a user