Files
bank-payment/account_banking_sepa_direct_debit/models/common.py
Alexis de Lattre bee3093841 Start to port bank-payment to v9 (with a lot of improvements) during the Sorrento Code sprint 2016
Improvements include:
- full re-organisation of modules and big re-organisation of the code
- simplification of the code related to the fact that support for direct debit is now in t
he base module, not added by an optional module account_direct_debit (module was removed)
- new design of the wizard to select move lines to pay
- support for non-SEPA file transfer-
- support for German direct debit SEPA files (fixes bug #129)
- remove workflow of payment.order

This port to v9 is not finished... there is still a lot of work:
- finish the code of account_payment_order/wizard/account_payment_line_create.py
- port account_banking_payment_transfer and integrate it inside account_payment_order
- fix bugs
- clean-up code, remove dead code
- test in several complex scenarios
2016-04-30 01:46:34 +02:00

40 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
logger = logging.getLogger(__name__)
def is_sepa_creditor_identifier_valid(sepa_creditor_identifier):
"""Check if SEPA Creditor Identifier is valid
@param sepa_creditor_identifier: SEPA Creditor Identifier as str
or unicode
@return: True if valid, False otherwise
"""
if not isinstance(sepa_creditor_identifier, (str, unicode)):
return False
try:
sci = str(sepa_creditor_identifier).lower()
except:
logger.warning(
"SEPA Creditor ID should contain only ASCII caracters.")
return False
if len(sci) < 9:
return False
before_replacement = sci[7:] + sci[0:2] + '00'
logger.debug(
"SEPA ID check before_replacement = %s" % before_replacement)
after_replacement = ''
for char in before_replacement:
if char.isalpha():
after_replacement += str(ord(char) - 87)
else:
after_replacement += char
logger.debug(
"SEPA ID check after_replacement = %s" % after_replacement)
return int(sci[2:4]) == (98 - (int(after_replacement) % 97))