bank-payment/account_banking_sepa_direct_debit/models/res_company.py

33 lines
1.2 KiB
Python
Raw Permalink Normal View History

2021-03-12 16:21:19 +00:00
# Copyright 2013-2016 Akretion - Alexis de Lattre
# Copyright 2014 Tecnativa - Pedro M. Baeza
# Copyright 2016 Tecnativa - Antonio Espinosa
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from stdnum.eu.at_02 import is_valid
from flectra import _, api, fields, models
from flectra.exceptions import ValidationError
class ResCompany(models.Model):
_inherit = "res.company"
sepa_creditor_identifier = fields.Char(
string="SEPA Creditor Identifier",
size=35,
help="Enter the Creditor Identifier that has been attributed to your "
"company to make SEPA Direct Debits. This identifier is composed "
"of :\n- your country ISO code (2 letters)\n- a 2-digits "
"checkum\n- a 3-letters business code\n- a country-specific "
"identifier",
)
@api.constrains("sepa_creditor_identifier")
def _check_sepa_creditor_identifier(self):
for company in self:
ics = company.sepa_creditor_identifier
if ics and not is_valid(ics):
raise ValidationError(
_("The SEPA Creditor Identifier '%s' is invalid.") % ics
)