From 287c05c4c32be02fb2fd7286375928239c74d33f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 9 Nov 2015 23:30:18 +0100 Subject: [PATCH] Add constraints on BIC length (8 or 11 chars) --- .../models/__init__.py | 1 + .../models/res_partner_bank.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 account_banking_payment_export/models/res_partner_bank.py diff --git a/account_banking_payment_export/models/__init__.py b/account_banking_payment_export/models/__init__.py index 738dcdbfd..f9da02f9f 100644 --- a/account_banking_payment_export/models/__init__.py +++ b/account_banking_payment_export/models/__init__.py @@ -8,3 +8,4 @@ from . import account_move_line from . import account_invoice from . import bank_payment_line from . import payment_line +from . import res_partner_bank diff --git a/account_banking_payment_export/models/res_partner_bank.py b/account_banking_payment_export/models/res_partner_bank.py new file mode 100644 index 000000000..efa2aba70 --- /dev/null +++ b/account_banking_payment_export/models/res_partner_bank.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api, _ +from openerp.exceptions import ValidationError + + +class ResPartnerBank(models.Model): + _inherit = 'res.partner.bank' + + @api.multi + @api.constrains('bank_bic') + def check_bic_length(self): + for pbank in self: + if pbank.bank_bic and len(pbank.bank_bic) not in (8, 11): + raise ValidationError(_( + "A valid BIC contains 8 or 11 caracters. The BIC '%s' " + "contains %d caracters, so it is not valid.") + % (pbank.bank_bic, len(pbank.bank_bic))) + + +class ResBank(models.Model): + _inherit = 'res.bank' + + @api.multi + @api.constrains('bic') + def check_bic_length(self): + for bank in self: + if bank.bic and len(bank.bic) not in (8, 11): + raise ValidationError(_( + "A valid BIC contains 8 or 11 caracters. The BIC '%s' " + "contains %d caracters, so it is not valid.") + % (bank.bic, len(bank.bic)))