mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[MIG] migrate account_bank_statement_import_ofx to V11
- add #136 patch
This commit is contained in:
committed by
Alexis de Lattre
parent
28dd3d3a0e
commit
f8abc3d359
@@ -22,7 +22,7 @@ Usage
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/174/10.0
|
||||
:target: https://runbot.odoo-community.org/runbot/174/11.0
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
@@ -48,6 +48,7 @@ Contributors
|
||||
* Laurent Mignon <laurent.mignon@acsone.eu>
|
||||
* Ronald Portier <rportier@therp.nl>
|
||||
* Sylvain LE GAL <https://twitter.com/legalsylvain>
|
||||
* Nicolas JEUDY <https://github.com/njeudy>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import wizard
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': 'Import OFX Bank Statement',
|
||||
'category': 'Banking addons',
|
||||
'version': '10.0.1.0.0',
|
||||
'version': '11.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Odoo SA,'
|
||||
'Akretion,'
|
||||
'La Louve,'
|
||||
'GRAP,'
|
||||
'Nicolas JEUDY,'
|
||||
'Odoo Community Association (OCA)',
|
||||
'website': 'https://odoo-community.org/',
|
||||
'depends': [
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import test_import_bank_statement
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.modules.module import get_module_resource
|
||||
import base64
|
||||
|
||||
|
||||
class TestOfxFile(TransactionCase):
|
||||
@@ -12,6 +12,7 @@ class TestOfxFile(TransactionCase):
|
||||
super(TestOfxFile, self).setUp()
|
||||
self.absi_model = self.env['account.bank.statement.import']
|
||||
self.abs_model = self.env['account.bank.statement']
|
||||
self.j_model = self.env['account.journal']
|
||||
self.absl_model = self.env['account.bank.statement.line']
|
||||
cur = self.env.ref('base.USD')
|
||||
self.env.ref('base.main_company').currency_id = cur.id
|
||||
@@ -20,29 +21,66 @@ class TestOfxFile(TransactionCase):
|
||||
'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': 'Bank Journal TEST OFX',
|
||||
'code': 'BNK12',
|
||||
'type': 'bank',
|
||||
'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 = base64.b64encode(open(ofx_file_path, 'rb').read())
|
||||
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):
|
||||
ofx_file_path = get_module_resource(
|
||||
'account_bank_statement_import_ofx',
|
||||
'tests/test_ofx_file/', 'test_ofx.ofx')
|
||||
ofx_file = open(ofx_file_path, 'rb').read().encode('base64')
|
||||
ofx_file = base64.b64encode(open(ofx_file_path, 'rb').read())
|
||||
bank_statement = self.absi_model.create(
|
||||
dict(data_file=ofx_file))
|
||||
bank_statement.import_file()
|
||||
bank_st_record = self.abs_model.search(
|
||||
[('name', 'like', '123456')])[0]
|
||||
self.assertEquals(bank_st_record.balance_start, 2516.56)
|
||||
self.assertEquals(bank_st_record.balance_end_real, 2156.56)
|
||||
self.assertEqual(bank_st_record.balance_start, 2516.56)
|
||||
self.assertEqual(bank_st_record.balance_end_real, 2156.56)
|
||||
|
||||
line = self.absl_model.search([
|
||||
('name', '=', 'Agrolait'),
|
||||
('statement_id', '=', bank_st_record.id)])[0]
|
||||
self.assertEquals(line.ref, '219378')
|
||||
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 = base64.b64encode(open(ofx_file_path, 'rb').read())
|
||||
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()
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -1,2 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import account_bank_statement_import
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import StringIO
|
||||
import io
|
||||
|
||||
from odoo import api, models, _
|
||||
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__)
|
||||
|
||||
@@ -18,12 +18,28 @@ except ImportError:
|
||||
class AccountBankStatementImport(models.TransientModel):
|
||||
_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
|
||||
def _check_ofx(self, data_file):
|
||||
if not OfxParser:
|
||||
return False
|
||||
try:
|
||||
ofx = OfxParser.parse(StringIO.StringIO(data_file))
|
||||
ofx = OfxParser.parse(io.StringIO(data_file.decode('utf-8')))
|
||||
except Exception as e:
|
||||
_logger.debug(e)
|
||||
return False
|
||||
@@ -61,7 +77,7 @@ class AccountBankStatementImport(models.TransientModel):
|
||||
if vals:
|
||||
transactions.append(vals)
|
||||
total_amt += vals['amount']
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise UserError(_(
|
||||
"The following problem occurred during import. "
|
||||
"The file might not be valid.\n\n %s") % e.message)
|
||||
|
||||
Reference in New Issue
Block a user