Browse Source

Merge pull request #136 from njeudy/10-ofx-account-number-saniteze-iban

[10.0] Find correct bank account when account is IBAN
pull/170/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
264c372a66
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      account_bank_statement_import_ofx/README.rst
  2. 1
      account_bank_statement_import_ofx/__manifest__.py
  3. 38
      account_bank_statement_import_ofx/tests/test_import_bank_statement.py
  4. 101
      account_bank_statement_import_ofx/tests/test_ofx_file/test_ofx_iban.ofx
  5. 100
      account_bank_statement_import_ofx/tests/test_ofx_file/test_ofx_wrong.ofx
  6. 20
      account_bank_statement_import_ofx/wizard/account_bank_statement_import.py

1
account_bank_statement_import_ofx/README.rst

@ -48,6 +48,7 @@ Contributors
* Laurent Mignon <laurent.mignon@acsone.eu> * Laurent Mignon <laurent.mignon@acsone.eu>
* Ronald Portier <rportier@therp.nl> * Ronald Portier <rportier@therp.nl>
* Sylvain LE GAL <https://twitter.com/legalsylvain> * Sylvain LE GAL <https://twitter.com/legalsylvain>
* Nicolas JEUDY <https://github.com/njeudy>
Maintainer Maintainer
---------- ----------

1
account_bank_statement_import_ofx/__manifest__.py

@ -8,6 +8,7 @@
'Akretion,' 'Akretion,'
'La Louve,' 'La Louve,'
'GRAP,' 'GRAP,'
'Nicolas JEUDY,'
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
'website': 'https://odoo-community.org/', 'website': 'https://odoo-community.org/',
'depends': [ 'depends': [

38
account_bank_statement_import_ofx/tests/test_import_bank_statement.py

@ -12,6 +12,7 @@ class TestOfxFile(TransactionCase):
super(TestOfxFile, self).setUp() super(TestOfxFile, self).setUp()
self.absi_model = self.env['account.bank.statement.import'] self.absi_model = self.env['account.bank.statement.import']
self.abs_model = self.env['account.bank.statement'] self.abs_model = self.env['account.bank.statement']
self.j_model = self.env['account.journal']
self.absl_model = self.env['account.bank.statement.line'] self.absl_model = self.env['account.bank.statement.line']
cur = self.env.ref('base.USD') cur = self.env.ref('base.USD')
self.env.ref('base.main_company').currency_id = cur.id self.env.ref('base.main_company').currency_id = cur.id
@ -28,6 +29,29 @@ class TestOfxFile(TransactionCase):
'bank_account_id': bank.id, 'bank_account_id': bank.id,
}) })
bank_iban_ofx = self.env['res.partner.bank'].create({
'acc_number': 'FR7630001007941234567890185',
'partner_id': self.env.ref('base.main_partner').id,
'company_id': self.env.ref('base.main_company').id,
'bank_id': self.env.ref('base.res_bank_1').id,
})
self.env['account.journal'].create({
'name': 'FR7630001007941234567890185',
'code': 'BNK13',
'type': 'bank',
'bank_account_id': bank_iban_ofx.id,
})
def test_wrong_ofx_file_import(self):
ofx_file_path = get_module_resource(
'account_bank_statement_import_ofx',
'tests/test_ofx_file/', 'test_ofx_wrong.ofx')
ofx_file_wrong = open(ofx_file_path, 'rb').read().encode('base64')
bank_statement = self.absi_model.create(
dict(data_file=ofx_file_wrong))
self.assertFalse(bank_statement._check_ofx(data_file=ofx_file_wrong))
def test_ofx_file_import(self): def test_ofx_file_import(self):
ofx_file_path = get_module_resource( ofx_file_path = get_module_resource(
'account_bank_statement_import_ofx', 'account_bank_statement_import_ofx',
@ -46,3 +70,17 @@ class TestOfxFile(TransactionCase):
('statement_id', '=', bank_st_record.id)])[0] ('statement_id', '=', bank_st_record.id)])[0]
self.assertEquals(line.ref, '219378') self.assertEquals(line.ref, '219378')
self.assertEquals(line.date, '2013-08-24') self.assertEquals(line.date, '2013-08-24')
def test_check_journal_bank_account(self):
ofx_file_path = get_module_resource(
'account_bank_statement_import_ofx',
'tests/test_ofx_file/', 'test_ofx_iban.ofx')
ofx_file = open(ofx_file_path, 'rb').read().encode('base64')
bank_st = self.absi_model.create(
dict(data_file=ofx_file))
journal_iban_ofx = self.j_model.search([
('name', '=', 'FR7630001007941234567890185')])
res = bank_st._check_journal_bank_account(journal_iban_ofx,
'12345678901')
self.assertTrue(res)
bank_st.with_context(journal_id=journal_iban_ofx.id).import_file()

101
account_bank_statement_import_ofx/tests/test_ofx_file/test_ofx_iban.ofx

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="ASCII"?>
<?OFX OFXHEADER="200" VERSION="211" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<DTSERVER>20130831165153.000[-8:PST]</DTSERVER>
<LANGUAGE>ENG</LANGUAGE>
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>0</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<STMTRS>
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>30001</BANKID>
<BRANCHID>00794</BRANCHID>
<ACCTID>12345678901</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-80</TRNAMT>
<FITID>219378</FITID>
<NAME>Agrolait</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-90</TRNAMT>
<FITID>219379</FITID>
<NAME>China Export</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-100</TRNAMT>
<FITID>219380</FITID>
<NAME>Axelor Scuba</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-90</TRNAMT>
<FITID>219381</FITID>
<NAME>China Scuba</NAME>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>2156.56</BALAMT>
<DTASOF>20130831165153</DTASOF>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
<CREDITCARDMSGSRSV1>
<CCSTMTTRNRS>
<TRNUID>0</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<CCSTMTRS>
<CURDEF>USD</CURDEF>
<CCACCTFROM>
<ACCTID>123412341234</ACCTID>
</CCACCTFROM>
<BANKTRANLIST>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>-562.00</BALAMT>
<DTASOF>20130831165153</DTASOF>
</LEDGERBAL>
</CCSTMTRS>
</CCSTMTTRNRS>
</CREDITCARDMSGSRSV1>
</OFX>

100
account_bank_statement_import_ofx/tests/test_ofx_file/test_ofx_wrong.ofx

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="ASCII"?>
<?OFX OFXHEADER="200" VERSION="211" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<DTSERVER>20130831165153.000[-8:PST]</DTSERVER>
<LANGUAGE>ENG</LANGUAGE>
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>0</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<STMTRS>
<!-- <CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>000000123</BANKID>
<ACCTID>123456</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM> -->
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-80</TRNAMT>
<FITID>219378</FITID>
<NAME>Agrolait</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<!-- <DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-90</TRNAMT>
<FITID>219379</FITID> -->
<NAME>China Export</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-100</TRNAMT>
<FITID>219380</FITID>
<NAME>Axelor Scuba</NAME>
</STMTTRN>
</BANKTRANLIST>
<BANKTRANLIST>
<DTSTART>20130801</DTSTART>
<DTEND>20130831165153.000[-8:PST]</DTEND>
<STMTTRN>
<TRNTYPE>POS</TRNTYPE>
<DTPOSTED>20130824080000</DTPOSTED>
<TRNAMT>-90</TRNAMT>
<FITID>219381</FITID>
<NAME>China Scuba</NAME>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>2156.56</BALAMT>
<DTASOF>20130831165153</DTASOF>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
<CREDITCARDMSGSRSV1>
<CCSTMTTRNRS>
<TRNUID>0</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<CCSTMTRS>
<CURDEF>USD</CURDEF>
<CCACCTFROM>
<ACCTID>123412341234</ACCTID>
</CCACCTFROM>
<BANKTRANLIST>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>-562.00</BALAMT>
<DTASOF>20130831165153</DTASOF>
</LEDGERBAL>
</CCSTMTRS>
</CCSTMTTRNRS>
</CREDITCARDMSGSRSV1>
</OFX>

20
account_bank_statement_import_ofx/wizard/account_bank_statement_import.py

@ -5,6 +5,8 @@ import StringIO
from odoo import api, models, _ from odoo import api, models, _
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.addons.base_iban.models.res_partner_bank import _map_iban_template
from odoo.addons.base_iban.models.res_partner_bank import validate_iban
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -18,6 +20,22 @@ except ImportError:
class AccountBankStatementImport(models.TransientModel): class AccountBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import' _inherit = 'account.bank.statement.import'
def _check_journal_bank_account(self, journal, account_number):
res = super(
AccountBankStatementImport, self
)._check_journal_bank_account(journal, account_number)
if not res:
e_acc_num = journal.bank_account_id.sanitized_acc_number
e_acc_num = e_acc_num.replace(" ", "")
validate_iban(e_acc_num)
country_code = e_acc_num[:2].lower()
iban_template = _map_iban_template[country_code].replace(
" ", "")
e_acc_num = "".join(
[c for c, t in zip(e_acc_num, iban_template) if t == "C"])
res = (e_acc_num == account_number)
return res
@api.model @api.model
def _check_ofx(self, data_file): def _check_ofx(self, data_file):
if not OfxParser: if not OfxParser:
@ -61,7 +79,7 @@ class AccountBankStatementImport(models.TransientModel):
if vals: if vals:
transactions.append(vals) transactions.append(vals)
total_amt += vals['amount'] total_amt += vals['amount']
except Exception, e:
except Exception as e:
raise UserError(_( raise UserError(_(
"The following problem occurred during import. " "The following problem occurred during import. "
"The file might not be valid.\n\n %s") % e.message) "The file might not be valid.\n\n %s") % e.message)

Loading…
Cancel
Save