From 26fac7bfa76a4ab7246c5f19d5c9f6593cf52a99 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sat, 13 Jun 2015 01:20:18 +0200 Subject: [PATCH 1/4] [ENH] Support zip files. --- .../models/account_bank_statement_import.py | 33 ++++++++++++++++-- .../test_files/test-camt053.xml | 30 ++++++++-------- .../test_files/test-camt053.zip | Bin 0 -> 3111 bytes .../tests/test_import_bank_statement.py | 11 ++++-- .../mt940.py | 2 +- .../test_files/test-camt053.zip | Bin 0 -> 3111 bytes 6 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 account_bank_statement_import_camt/test_files/test-camt053.zip create mode 100644 bank_statement_parse_camt/test_files/test-camt053.zip diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index 9a8b9136..58d07c53 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/account_bank_statement_import/models/account_bank_statement_import.py @@ -2,6 +2,8 @@ """Framework for importing bank statement files.""" import logging import base64 +from StringIO import StringIO +from zipfile import ZipFile, BadZipfile # BadZipFile in Python >= 3.2 from openerp import api, models, fields from openerp.tools.translate import _ @@ -52,7 +54,7 @@ class AccountBankStatementImport(models.TransientModel): @api.multi def import_file(self): - """ Process the file chosen in the wizard, create bank statement(s) and + """Process the file chosen in the wizard, create bank statement(s) and go to reconciliation.""" self.ensure_one() data_file = base64.b64decode(self.data_file) @@ -71,13 +73,38 @@ class AccountBankStatementImport(models.TransientModel): 'type': 'ir.actions.client', } + @api.model + def _parse_all_files(self, data_file): + """Parse one file or multiple files from zip-file. + + Return array of statements for further processing. + """ + statements = [] + files = [data_file] + try: + with ZipFile(StringIO(data_file), 'r') as archive: + files = [ + archive.read(filename) for filename in archive.namelist() + if not filename.endswith('/') + ] + except BadZipfile: + pass + # Parse the file(s) + for import_file in files: + # The appropriate implementation module(s) returns the statements. + # Actually we don't care wether all the files have the same + # format. Although unlikely you might mix mt940 and camt files + # in one zipfile. + statements += self._parse_file(import_file) + return statements + @api.model def _import_file(self, data_file): """ Create bank statement(s) from file.""" # The appropriate implementation module returns the required data statement_ids = [] notifications = [] - parse_result = self._parse_file(data_file) + parse_result = self._parse_all_files(data_file) # Check for old version result, with separate currency and account if isinstance(parse_result, tuple) and len(parse_result) == 3: (currency_code, account_number, statements) = parse_result @@ -125,7 +152,7 @@ class AccountBankStatementImport(models.TransientModel): return self._create_bank_statement(stmt_vals) @api.model - def _parse_file(self, data_file): + def _parse_file(self, dummy_data_file): """ Each module adding a file support must extends this method. It processes the file if it can, returns super otherwise, resulting in a chain of responsability. diff --git a/account_bank_statement_import_camt/test_files/test-camt053.xml b/account_bank_statement_import_camt/test_files/test-camt053.xml index 1d74d81b..4a2a0473 100644 --- a/account_bank_statement_import_camt/test_files/test-camt053.xml +++ b/account_bank_statement_import_camt/test_files/test-camt053.xml @@ -2,15 +2,15 @@ TESTBANK/NL/1420561226673 - 2013-01-06T16:20:26.673Z + 2014-01-06T16:20:26.673Z 1234Test/1 2 - 2013-01-06T16:20:26.673Z + 2014-01-06T16:20:26.673Z - 2013-01-05T00:00:00.000Z - 2013-01-05T23:59:59.999Z + 2014-01-05T00:00:00.000Z + 2014-01-05T23:59:59.999Z @@ -32,7 +32,7 @@ 15568.27 CRDT
-
2013-01-05
+
2014-01-05
@@ -44,7 +44,7 @@ 15121.12 CRDT
-
2013-01-05
+
2014-01-05
@@ -52,10 +52,10 @@ DBIT BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -104,9 +104,9 @@ - Insurance policy 857239PERIOD 01.01.2013 - 31.12.2013 + Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014 - MKB Insurance 859239PERIOD 01.01.2013 - 31.12.2013 + MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014
@@ -116,10 +116,10 @@ true BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -182,10 +182,10 @@ CRDT BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -202,7 +202,7 @@ - INNDNL2U20130105000217200000708 + INNDNL2U20140105000217200000708 115 diff --git a/account_bank_statement_import_camt/test_files/test-camt053.zip b/account_bank_statement_import_camt/test_files/test-camt053.zip new file mode 100644 index 0000000000000000000000000000000000000000..ccf5b3c2ba72ad03cc137edcf2ee55f67b7a2952 GIT binary patch literal 3111 zcmeH}=T{S08pZ=5FccF7R764P14xk;5EP_{0RmY=5O4w{AVr!$C=oHlAWJhyReBE! zAqJ!U#$s;Q+O;qQmC7X$#CFp;S53XKp3 z@bIyK0Kng`kJ*<4=k&#UW|xqT(@Tov5YUyorl#QtnL>GL823Dkl9(M6fc0cI%(|Ni z6Q^GLcu71wsM2}%?CvjH!8b!s<&9$V%#|&29fp7$*Z6H3|gs9r@Iab`}w zn70^AGxt!43sw21&ugEeu5!s zB=aSvS|O$Bs(_1W`3N!7kW{?C+9uvd?a-AuvRv(>X!goeIdlV;b{mCeyP1vK$0=9p zhvGziT|Owbw0q_obsli0rv4Sr^-c(wMC`04QcZhDwWKHp@XFHQlHEbhsWMKSBZZOw zA}>C4#%A3WrP-sj`HDO4lA-;!yrBVX&3%#eOMKMU@+IV(nv7lhYS%{;$3{6@D@-?8 zj%$0W-f~sSJ^sQi^P9;MO$$IZFznJn;)6b5Ft;O?XIp3Wvr?Mxgx4Co_F1d*^z6>W z16A~WLf`!H5cIp~GA4ZCR{`G`WEw$zws*gec}$;&fZM zo5o5(B`9uG=!A2Ina*WDMms&g&>^6!qHt5;GqTVR1>*Ec+Z)I*wlOs-1v{7k(SD7cx&3TX>4UUU|z4aL*H}d*MEMlY`)`QpML{Lh>UZ>Y$ z#RRHb?tB{p^?Uws=MQd|l>2$Th%nhp47tF`Rx7B!RoxbGo{x9Ijt)~YQ+V444% zPzs&KG$xTJ)T2(Qz^8|QRB}mXgGS2uVz8>+^ZoN75^~j6MqhVW51<$wUzWDyF|J1 zirME@jT#|^OHAAz3aV0H+~Jxv^`tk-VY6f-Rl*g=@Y-F-Ba{e9gU80nOv-XmG14&C zV(E)5%on5Y=I7h_Gab0duA42{ST}8V<9on@o5adK;Lj4$TmL;iTZRlaNcE zF1&6LTv;hka~iWF8};~H>r~tMthOl-2An0f&eCUPY+h! z>c3ZOHlMoCRY`(}DnQqY19eBIViuA`HhKm_r5I4{dR+8rdB$SfS*>Oa_D7-8&b&W) z{U@*guX)YGD-Hakf-SLEya527J(Uu_PrqBYLI0@RzhO7R`d`NX9R>ex{Ae#A{?quM b!LVoiJE4HE2JwIY3-8{k*?V1uzi)p7q~E=A literal 0 HcmV?d00001 diff --git a/account_bank_statement_import_camt/tests/test_import_bank_statement.py b/account_bank_statement_import_camt/tests/test_import_bank_statement.py index 8a1694f0..d14aca96 100644 --- a/account_bank_statement_import_camt/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_camt/tests/test_import_bank_statement.py @@ -31,11 +31,10 @@ class TestImport(TestStatementFile): { 'remote_account': 'NL46ABNA0499998748', 'transferred_amount': -754.25, - 'value_date': '2013-01-05', + 'value_date': '2014-01-05', 'ref': '435005714488-ABNO33052620', }, ] - # statement name is account number + '-' + date of last 62F line: self._test_statement_import( 'account_bank_statement_import_camt', 'test-camt053.xml', '1234Test/1', @@ -43,3 +42,11 @@ class TestImport(TestStatementFile): start_balance=15568.27, end_balance=15121.12, transactions=transactions ) + + def test_zip_import(self): + """Test import of multiple statements from zip file.""" + self._test_statement_import( + 'account_bank_statement_import_camt', 'test-camt053.zip', + '1234Test/2', # Only name of first statement + local_account='NL77ABNA0574908765', + ) diff --git a/account_bank_statement_import_mt940_base/mt940.py b/account_bank_statement_import_mt940_base/mt940.py index 8677bc7c..9ddd9cef 100644 --- a/account_bank_statement_import_mt940_base/mt940.py +++ b/account_bank_statement_import_mt940_base/mt940.py @@ -111,7 +111,7 @@ class MT940(object): This in fact uses the ING syntax, override in others.""" self.mt940_type = 'General' self.header_lines = 3 # Number of lines to skip - self.header_regex = '^0000 01INGBNL2AXXXX|^{1' + self.header_regex = '^0000 01INGBNL2AXXXX|^{1' # Start of header self.footer_regex = '^-}$|^-XXX$' # Stop processing on seeing this self.tag_regex = '^:[0-9]{2}[A-Z]*:' # Start of new tag self.current_statement = None diff --git a/bank_statement_parse_camt/test_files/test-camt053.zip b/bank_statement_parse_camt/test_files/test-camt053.zip new file mode 100644 index 0000000000000000000000000000000000000000..ccf5b3c2ba72ad03cc137edcf2ee55f67b7a2952 GIT binary patch literal 3111 zcmeH}=T{S08pZ=5FccF7R764P14xk;5EP_{0RmY=5O4w{AVr!$C=oHlAWJhyReBE! zAqJ!U#$s;Q+O;qQmC7X$#CFp;S53XKp3 z@bIyK0Kng`kJ*<4=k&#UW|xqT(@Tov5YUyorl#QtnL>GL823Dkl9(M6fc0cI%(|Ni z6Q^GLcu71wsM2}%?CvjH!8b!s<&9$V%#|&29fp7$*Z6H3|gs9r@Iab`}w zn70^AGxt!43sw21&ugEeu5!s zB=aSvS|O$Bs(_1W`3N!7kW{?C+9uvd?a-AuvRv(>X!goeIdlV;b{mCeyP1vK$0=9p zhvGziT|Owbw0q_obsli0rv4Sr^-c(wMC`04QcZhDwWKHp@XFHQlHEbhsWMKSBZZOw zA}>C4#%A3WrP-sj`HDO4lA-;!yrBVX&3%#eOMKMU@+IV(nv7lhYS%{;$3{6@D@-?8 zj%$0W-f~sSJ^sQi^P9;MO$$IZFznJn;)6b5Ft;O?XIp3Wvr?Mxgx4Co_F1d*^z6>W z16A~WLf`!H5cIp~GA4ZCR{`G`WEw$zws*gec}$;&fZM zo5o5(B`9uG=!A2Ina*WDMms&g&>^6!qHt5;GqTVR1>*Ec+Z)I*wlOs-1v{7k(SD7cx&3TX>4UUU|z4aL*H}d*MEMlY`)`QpML{Lh>UZ>Y$ z#RRHb?tB{p^?Uws=MQd|l>2$Th%nhp47tF`Rx7B!RoxbGo{x9Ijt)~YQ+V444% zPzs&KG$xTJ)T2(Qz^8|QRB}mXgGS2uVz8>+^ZoN75^~j6MqhVW51<$wUzWDyF|J1 zirME@jT#|^OHAAz3aV0H+~Jxv^`tk-VY6f-Rl*g=@Y-F-Ba{e9gU80nOv-XmG14&C zV(E)5%on5Y=I7h_Gab0duA42{ST}8V<9on@o5adK;Lj4$TmL;iTZRlaNcE zF1&6LTv;hka~iWF8};~H>r~tMthOl-2An0f&eCUPY+h! z>c3ZOHlMoCRY`(}DnQqY19eBIViuA`HhKm_r5I4{dR+8rdB$SfS*>Oa_D7-8&b&W) z{U@*guX)YGD-Hakf-SLEya527J(Uu_PrqBYLI0@RzhO7R`d`NX9R>ex{Ae#A{?quM b!LVoiJE4HE2JwIY3-8{k*?V1uzi)p7q~E=A literal 0 HcmV?d00001 From f5f892ffa94f4b16592774f6df57f5fdd24ece2a Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Thu, 27 Aug 2015 19:20:55 +0200 Subject: [PATCH 2/4] [FIX] Make sure old style parse results are handled properly. --- account_bank_statement_import/__init__.py | 1 + account_bank_statement_import/__openerp__.py | 3 +- .../models/__init__.py | 2 +- .../models/account_bank_statement_import.py | 55 +++++++++++-------- account_bank_statement_import/parserlib.py | 2 +- .../__init__.py | 1 + .../__openerp__.py | 2 +- .../__init__.py | 1 + .../__openerp__.py | 2 +- .../tests/__init__.py | 4 +- .../__init__.py | 2 +- 11 files changed, 43 insertions(+), 32 deletions(-) diff --git a/account_bank_statement_import/__init__.py b/account_bank_statement_import/__init__.py index 0650744f..4213b8b1 100644 --- a/account_bank_statement_import/__init__.py +++ b/account_bank_statement_import/__init__.py @@ -1 +1,2 @@ +# -*- encoding: utf-8 -*- from . import models diff --git a/account_bank_statement_import/__openerp__.py b/account_bank_statement_import/__openerp__.py index b7a95570..31df646c 100644 --- a/account_bank_statement_import/__openerp__.py +++ b/account_bank_statement_import/__openerp__.py @@ -1,8 +1,9 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- { 'name': 'Account Bank Statement Import', 'category': 'Banking addons', 'version': '8.0.1.0.1', + 'license': 'AGPL-3', 'author': 'OpenERP SA,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import/models/__init__.py b/account_bank_statement_import/models/__init__.py index 3a3c51ad..7fbdca12 100644 --- a/account_bank_statement_import/models/__init__.py +++ b/account_bank_statement_import/models/__init__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- from . import res_partner_bank from . import account_bank_statement_import diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index 58d07c53..47a6f56a 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/account_bank_statement_import/models/account_bank_statement_import.py @@ -7,13 +7,14 @@ from zipfile import ZipFile, BadZipfile # BadZipFile in Python >= 3.2 from openerp import api, models, fields from openerp.tools.translate import _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError -_logger = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) # pylint: disable=invalid-name class AccountBankStatementLine(models.Model): """Extend model account.bank.statement.line.""" + # pylint: disable=too-many-public-methods _inherit = "account.bank.statement.line" # Ensure transactions can be imported only once (if the import format @@ -29,6 +30,7 @@ class AccountBankStatementLine(models.Model): class AccountBankStatementImport(models.TransientModel): """Extend model account.bank.statement.""" + # pylint: disable=too-many-public-methods _name = 'account.bank.statement.import' _description = 'Import Bank Statement' @@ -37,6 +39,7 @@ class AccountBankStatementImport(models.TransientModel): """ Return False if the journal_id can't be provided by the parsed file and must be provided by the wizard. See account_bank_statement_import_qif """ + # pylint: disable=no-self-use return True journal_id = fields.Many2one( @@ -58,8 +61,10 @@ class AccountBankStatementImport(models.TransientModel): go to reconciliation.""" self.ensure_one() data_file = base64.b64decode(self.data_file) + # pylint: disable=protected-access statement_ids, notifications = self.with_context( - active_id=self.id)._import_file(data_file) + active_id=self.id # pylint: disable=no-member + )._import_file(data_file) # dispatch to reconciliation interface action = self.env.ref( 'account.action_bank_reconcile_bank_statements') @@ -95,7 +100,16 @@ class AccountBankStatementImport(models.TransientModel): # Actually we don't care wether all the files have the same # format. Although unlikely you might mix mt940 and camt files # in one zipfile. - statements += self._parse_file(import_file) + parse_result = self._parse_file(import_file) + # Check for old version result, with separate currency and account + if isinstance(parse_result, tuple) and len(parse_result) == 3: + (currency_code, account_number, new_statements) = parse_result + for stmt_vals in new_statements: + stmt_vals['currency_code'] = currency_code + stmt_vals['account_number'] = account_number + else: + new_statements = parse_result + statements += new_statements return statements @api.model @@ -104,15 +118,7 @@ class AccountBankStatementImport(models.TransientModel): # The appropriate implementation module returns the required data statement_ids = [] notifications = [] - parse_result = self._parse_all_files(data_file) - # Check for old version result, with separate currency and account - if isinstance(parse_result, tuple) and len(parse_result) == 3: - (currency_code, account_number, statements) = parse_result - for stmt_vals in statements: - stmt_vals['currency_code'] = currency_code - stmt_vals['account_number'] = account_number - else: - statements = parse_result + statements = self._parse_all_files(data_file) # Check raw data: self._check_parsed_data(statements) # Import all statements: @@ -123,7 +129,7 @@ class AccountBankStatementImport(models.TransientModel): statement_ids.append(statement_id) notifications.append(new_notifications) if len(statement_ids) == 0: - raise Warning(_('You have already imported that file.')) + raise UserError(_('You have already imported that file.')) return statement_ids, notifications @api.model @@ -144,7 +150,7 @@ class AccountBankStatementImport(models.TransientModel): journal_id = self._get_journal(currency_id, bank_account_id) # By now journal and account_number must be known if not journal_id: - raise Warning(_('Can not determine journal for import.')) + raise UserError(_('Can not determine journal for import.')) # Prepare statement data to be used for bank statements creation stmt_vals = self._complete_statement( stmt_vals, journal_id, account_number) @@ -152,7 +158,9 @@ class AccountBankStatementImport(models.TransientModel): return self._create_bank_statement(stmt_vals) @api.model - def _parse_file(self, dummy_data_file): + def _parse_file(self, data_file): + # pylint: disable=no-self-use + # pylint: disable=unused-argument """ Each module adding a file support must extends this method. It processes the file if it can, returns super otherwise, resulting in a chain of responsability. @@ -182,21 +190,22 @@ class AccountBankStatementImport(models.TransientModel): -o 'partner_name': string -o 'ref': string """ - raise Warning(_( + raise UserError(_( 'Could not make sense of the given file.\n' 'Did you install the module to support this type of file?' )) @api.model def _check_parsed_data(self, statements): + # pylint: disable=no-self-use """ Basic and structural verifications """ if len(statements) == 0: - raise Warning(_('This file doesn\'t contain any statement.')) + raise UserError(_('This file doesn\'t contain any statement.')) for stmt_vals in statements: if 'transactions' in stmt_vals and stmt_vals['transactions']: return # If we get here, no transaction was found: - raise Warning(_('This file doesn\'t contain any transaction.')) + raise UserError(_('This file doesn\'t contain any transaction.')) @api.model def _find_currency_id(self, currency_code): @@ -207,7 +216,7 @@ class AccountBankStatementImport(models.TransientModel): if currency_ids: return currency_ids[0].id else: - raise Warning(_( + raise UserError(_( 'Statement has invalid currency code %s') % currency_code) # if no currency_code is provided, we'll use the company currency return self.env.user.company_id.currency_id.id @@ -234,7 +243,7 @@ class AccountBankStatementImport(models.TransientModel): if journal_id: if (bank_account.journal_id.id and bank_account.journal_id.id != journal_id): - raise Warning( + raise UserError( _('The account of this statement is linked to ' 'another journal.')) if not bank_account.journal_id.id: @@ -257,7 +266,7 @@ class AccountBankStatementImport(models.TransientModel): currency_id, journal_currency_id ) - raise Warning(_( + raise UserError(_( 'The currency of the bank statement is not ' 'the same as the currency of the journal !' )) @@ -271,7 +280,7 @@ class AccountBankStatementImport(models.TransientModel): currency_id, company_currency_id ) - raise Warning(_( + raise UserError(_( 'The currency of the bank statement is not ' 'the same as the company currency !' )) diff --git a/account_bank_statement_import/parserlib.py b/account_bank_statement_import/parserlib.py index 49bb0e78..ff8012dc 100644 --- a/account_bank_statement_import/parserlib.py +++ b/account_bank_statement_import/parserlib.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- """Classes and definitions used in parsing bank statements.""" ############################################################################## # diff --git a/account_bank_statement_import_mt940_base/__init__.py b/account_bank_statement_import_mt940_base/__init__.py index d31f98c6..c9fbf3a8 100644 --- a/account_bank_statement_import_mt940_base/__init__.py +++ b/account_bank_statement_import_mt940_base/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- from . import mt940 diff --git a/account_bank_statement_import_mt940_base/__openerp__.py b/account_bank_statement_import_mt940_base/__openerp__.py index 6cef8dcf..c701d421 100644 --- a/account_bank_statement_import_mt940_base/__openerp__.py +++ b/account_bank_statement_import_mt940_base/__openerp__.py @@ -27,5 +27,5 @@ 'depends': [ 'account_bank_statement_import', ], - 'installable': True + 'installable': True, } diff --git a/account_bank_statement_import_mt940_nl_ing/__init__.py b/account_bank_statement_import_mt940_nl_ing/__init__.py index 7dafcd16..5dfe830f 100644 --- a/account_bank_statement_import_mt940_nl_ing/__init__.py +++ b/account_bank_statement_import_mt940_nl_ing/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- from . import account_bank_statement_import diff --git a/account_bank_statement_import_mt940_nl_ing/__openerp__.py b/account_bank_statement_import_mt940_nl_ing/__openerp__.py index 42369552..fa91932d 100644 --- a/account_bank_statement_import_mt940_nl_ing/__openerp__.py +++ b/account_bank_statement_import_mt940_nl_ing/__openerp__.py @@ -30,5 +30,5 @@ 'demo': [ 'demo/demo_data.xml', ], - 'installable': True + 'installable': True, } diff --git a/account_bank_statement_import_mt940_nl_ing/tests/__init__.py b/account_bank_statement_import_mt940_nl_ing/tests/__init__.py index 37fdfc8b..6d7e2f90 100644 --- a/account_bank_statement_import_mt940_nl_ing/tests/__init__.py +++ b/account_bank_statement_import_mt940_nl_ing/tests/__init__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- """Test import of bank statement for MT940 ING.""" ############################################################################## # @@ -6,8 +6,6 @@ # # All other contributions are (C) by their respective contributors # -# All Rights Reserved -# # 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 diff --git a/account_bank_statement_import_mt940_nl_rabo/__init__.py b/account_bank_statement_import_mt940_nl_rabo/__init__.py index 274e1843..c6d596f3 100644 --- a/account_bank_statement_import_mt940_nl_rabo/__init__.py +++ b/account_bank_statement_import_mt940_nl_rabo/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2014-2015 Therp BV (). +# Copyright (C) 2014-2015 Therp BV . # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as From 7d12ce19f12709106d855ae5667c7a437af3352c Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Fri, 2 Oct 2015 00:12:32 +0200 Subject: [PATCH 3/4] [FIX] Import exceptions.Warning as UserError. This according to OCA guidelines. Also reformat README.rst to keep lines within limit. --- account_bank_statement_import/__openerp__.py | 4 +- .../models/account_bank_statement_import.py | 5 ++- .../tests/test_import_bank_statement.py | 6 +-- .../__openerp__.py | 2 +- .../__openerp__.py | 2 +- .../README.rst | 2 +- .../__openerp__.py | 2 +- .../__openerp__.py | 3 +- .../__openerp__.py | 5 ++- .../account_bank_statement_import_ofx.py | 8 ++-- .../__openerp__.py | 4 +- .../account_bank_statement_import_qif.py | 10 +++-- .../__openerp__.py | 36 +++++++----------- .../test_files/test-camt053.zip | Bin 3111 -> 0 bytes base_bank_account_number_unique/README.rst | 27 ++++++++++--- .../__openerp__.py | 22 +++++------ base_bank_account_number_unique/hooks.py | 7 ++-- .../test_base_bank_account_number_unique.py | 4 +- 18 files changed, 82 insertions(+), 67 deletions(-) delete mode 100644 bank_statement_parse_camt/test_files/test-camt053.zip diff --git a/account_bank_statement_import/__openerp__.py b/account_bank_statement_import/__openerp__.py index 31df646c..6961e9a5 100644 --- a/account_bank_statement_import/__openerp__.py +++ b/account_bank_statement_import/__openerp__.py @@ -2,14 +2,14 @@ { 'name': 'Account Bank Statement Import', 'category': 'Banking addons', - 'version': '8.0.1.0.1', + 'version': '8.0.1.0.2', 'license': 'AGPL-3', 'author': 'OpenERP SA,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/bank-statement-import', 'depends': ['account'], 'data': [ - "views/account_config_settings.xml", + 'views/account_config_settings.xml', 'views/account_bank_statement_import_view.xml', ], 'demo': [ diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index 47a6f56a..a9e07f1d 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/account_bank_statement_import/models/account_bank_statement_import.py @@ -144,8 +144,9 @@ class AccountBankStatementImport(models.TransientModel): currency_id = self._find_currency_id(currency_code) bank_account_id = self._find_bank_account_id(account_number) if not bank_account_id and account_number: - raise Warning(_('Can not find the account number %s.') % - account_number) + raise UserError( + _('Can not find the account number %s.') % account_number + ) # Find the bank journal journal_id = self._get_journal(currency_id, bank_account_id) # By now journal and account_number must be known diff --git a/account_bank_statement_import/tests/test_import_bank_statement.py b/account_bank_statement_import/tests/test_import_bank_statement.py index e32051a4..42021ab8 100644 --- a/account_bank_statement_import/tests/test_import_bank_statement.py +++ b/account_bank_statement_import/tests/test_import_bank_statement.py @@ -23,7 +23,7 @@ # ############################################################################## from openerp.tests.common import TransactionCase -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError class TestAccountBankStatementImport(TransactionCase): @@ -68,12 +68,12 @@ class TestAccountBankStatementImport(TransactionCase): stmt_vals = { 'currency_code': 'EUR', 'account_number': '123456789'} - with self.assertRaises(Warning) as e: + with self.assertRaises(UserError) as e: self.statement_import_model._import_statement(stmt_vals.copy()) self.assertEqual(e.exception.message, 'Can not find the account number 123456789.') self.statement_import_model._create_bank_account('123456789') - with self.assertRaises(Warning) as e: + with self.assertRaises(UserError) as e: self.statement_import_model._import_statement(stmt_vals.copy()) self.assertEqual(e.exception.message, 'Can not determine journal for import.') diff --git a/account_bank_statement_import_camt/__openerp__.py b/account_bank_statement_import_camt/__openerp__.py index 47113f36..d54abd61 100644 --- a/account_bank_statement_import_camt/__openerp__.py +++ b/account_bank_statement_import_camt/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'CAMT Format Bank Statements Import', - 'version': '8.0.0.3.0', + 'version': '8.0.1.0.4', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_mt940_base/__openerp__.py b/account_bank_statement_import_mt940_base/__openerp__.py index c701d421..d821ce37 100644 --- a/account_bank_statement_import_mt940_base/__openerp__.py +++ b/account_bank_statement_import_mt940_base/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'MT940 Bank Statements Import', - 'version': '8.0.1.1.0', + 'version': '8.0.1.1.1', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_mt940_nl_ing/README.rst b/account_bank_statement_import_mt940_nl_ing/README.rst index 631543d2..2f9107ec 100644 --- a/account_bank_statement_import_mt940_nl_ing/README.rst +++ b/account_bank_statement_import_mt940_nl_ing/README.rst @@ -7,7 +7,7 @@ Import MT940 IBAN ING Bank Statements This module allows you to import the MT940 IBAN files from the Dutch ING bank in Odoo as bank statements. The specifications are published at: - https://www.ing.nl/media/ING_ming_mt940s_24_juli_tcm162-46356.pdf +https://www.ing.nl/media/ING_ming_mt940s_24_juli_tcm162-46356.pdf and were last updated august 2014. Known issues / Roadmap diff --git a/account_bank_statement_import_mt940_nl_ing/__openerp__.py b/account_bank_statement_import_mt940_nl_ing/__openerp__.py index fa91932d..6cad8a5c 100644 --- a/account_bank_statement_import_mt940_nl_ing/__openerp__.py +++ b/account_bank_statement_import_mt940_nl_ing/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'MT940 IBAN ING Format Bank Statements Import', - 'version': '8.0.0.3.0', + 'version': '8.0.1.0.4', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_mt940_nl_rabo/__openerp__.py b/account_bank_statement_import_mt940_nl_rabo/__openerp__.py index c01e7e3d..90f0239b 100644 --- a/account_bank_statement_import_mt940_nl_rabo/__openerp__.py +++ b/account_bank_statement_import_mt940_nl_rabo/__openerp__.py @@ -19,7 +19,8 @@ ############################################################################## { 'name': 'MT940 import for dutch Rabobank', - 'version': '8.0.1.1.0', + 'version': '8.0.1.1.1', + 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', 'category': 'Banking addons', diff --git a/account_bank_statement_import_ofx/__openerp__.py b/account_bank_statement_import_ofx/__openerp__.py index 329859e7..6d9c3278 100644 --- a/account_bank_statement_import_ofx/__openerp__.py +++ b/account_bank_statement_import_ofx/__openerp__.py @@ -1,8 +1,9 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- { 'name': 'Import OFX Bank Statement', 'category': 'Banking addons', - 'version': '8.0.1.0.0', + 'version': '8.0.1.0.1', + 'license': 'AGPL-3', 'author': 'OpenERP SA,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py index 9358ae12..b03af725 100644 --- a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py +++ b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py @@ -5,7 +5,7 @@ import StringIO from openerp import api, models from openerp.tools.translate import _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError _logger = logging.getLogger(__name__) @@ -64,8 +64,10 @@ class AccountBankStatementImport(models.TransientModel): total_amt += float(transaction.amount) transactions.append(vals_line) except Exception, e: - raise Warning(_("The following problem occurred during import. " - "The file might not be valid.\n\n %s" % e.message)) + raise UserError(_( + "The following problem occurred during import. " + "The file might not be valid.\n\n %s" % e.message + )) vals_bank_statement = { 'name': ofx.account.routing_number, diff --git a/account_bank_statement_import_qif/__openerp__.py b/account_bank_statement_import_qif/__openerp__.py index 14a81a06..fb33246e 100644 --- a/account_bank_statement_import_qif/__openerp__.py +++ b/account_bank_statement_import_qif/__openerp__.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- - { 'name': 'Import QIF Bank Statement', 'category': 'Banking addons', - 'version': '8.0.1.0.0', + 'version': '8.0.1.0.1', + 'license': 'AGPL-3', 'author': 'OpenERP SA,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_qif/account_bank_statement_import_qif.py b/account_bank_statement_import_qif/account_bank_statement_import_qif.py index 0b9061e4..b217e65b 100644 --- a/account_bank_statement_import_qif/account_bank_statement_import_qif.py +++ b/account_bank_statement_import_qif/account_bank_statement_import_qif.py @@ -5,7 +5,7 @@ import StringIO from openerp.tools.translate import _ from openerp import api, models -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError class AccountBankStatementImport(models.TransientModel): @@ -36,7 +36,7 @@ class AccountBankStatementImport(models.TransientModel): header = data_list[0].strip() header = header.split(":")[1] except: - raise Warning(_('Could not decipher the QIF file.')) + raise UserError(_('Could not decipher the QIF file.')) transactions = [] vals_line = {} total = 0 @@ -80,8 +80,10 @@ class AccountBankStatementImport(models.TransientModel): else: pass else: - raise Warning(_('This file is either not a bank statement or is ' - 'not correctly formed.')) + raise UserError(_( + "This file is either not a bank statement or is " + "not correctly formed." + )) vals_bank_statement.update({ 'balance_end_real': total, diff --git a/account_bank_statement_import_save_file/__openerp__.py b/account_bank_statement_import_save_file/__openerp__.py index bdf5a388..20c735c1 100644 --- a/account_bank_statement_import_save_file/__openerp__.py +++ b/account_bank_statement_import_save_file/__openerp__.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Therp BV . +# Copyright (C) 2015 Therp BV . # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,27 +18,20 @@ # ############################################################################## { - "name": "Save imported bank statements", - "version": "8.0.1.0.0", - "author": "Therp BV", - "license": "AGPL-3", - "category": "Accounting & Finance", - "summary": "Keep imported bank statements as raw data", - "depends": [ + 'name': 'Save imported bank statements', + 'version': '8.0.1.0.1', + 'author': 'Odoo Community Association (OCA), Therp BV', + 'license': 'AGPL-3', + 'category': 'Banking addons', + 'summary': 'Keep imported bank statements as raw data', + 'depends': [ 'account_bank_statement_import', ], - "data": [ - "views/account_bank_statement.xml", + 'data': [ + 'views/account_bank_statement.xml', ], - "qweb": [ - ], - "test": [ - ], - "post_init_hook": '_post_init_hook', - "auto_install": False, - "installable": True, - "application": False, - "external_dependencies": { - 'python': [], - }, + 'post_init_hook': '_post_init_hook', + 'auto_install': False, + 'installable': True, + 'application': False, } diff --git a/bank_statement_parse_camt/test_files/test-camt053.zip b/bank_statement_parse_camt/test_files/test-camt053.zip deleted file mode 100644 index ccf5b3c2ba72ad03cc137edcf2ee55f67b7a2952..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3111 zcmeH}=T{S08pZ=5FccF7R764P14xk;5EP_{0RmY=5O4w{AVr!$C=oHlAWJhyReBE! zAqJ!U#$s;Q+O;qQmC7X$#CFp;S53XKp3 z@bIyK0Kng`kJ*<4=k&#UW|xqT(@Tov5YUyorl#QtnL>GL823Dkl9(M6fc0cI%(|Ni z6Q^GLcu71wsM2}%?CvjH!8b!s<&9$V%#|&29fp7$*Z6H3|gs9r@Iab`}w zn70^AGxt!43sw21&ugEeu5!s zB=aSvS|O$Bs(_1W`3N!7kW{?C+9uvd?a-AuvRv(>X!goeIdlV;b{mCeyP1vK$0=9p zhvGziT|Owbw0q_obsli0rv4Sr^-c(wMC`04QcZhDwWKHp@XFHQlHEbhsWMKSBZZOw zA}>C4#%A3WrP-sj`HDO4lA-;!yrBVX&3%#eOMKMU@+IV(nv7lhYS%{;$3{6@D@-?8 zj%$0W-f~sSJ^sQi^P9;MO$$IZFznJn;)6b5Ft;O?XIp3Wvr?Mxgx4Co_F1d*^z6>W z16A~WLf`!H5cIp~GA4ZCR{`G`WEw$zws*gec}$;&fZM zo5o5(B`9uG=!A2Ina*WDMms&g&>^6!qHt5;GqTVR1>*Ec+Z)I*wlOs-1v{7k(SD7cx&3TX>4UUU|z4aL*H}d*MEMlY`)`QpML{Lh>UZ>Y$ z#RRHb?tB{p^?Uws=MQd|l>2$Th%nhp47tF`Rx7B!RoxbGo{x9Ijt)~YQ+V444% zPzs&KG$xTJ)T2(Qz^8|QRB}mXgGS2uVz8>+^ZoN75^~j6MqhVW51<$wUzWDyF|J1 zirME@jT#|^OHAAz3aV0H+~Jxv^`tk-VY6f-Rl*g=@Y-F-Ba{e9gU80nOv-XmG14&C zV(E)5%on5Y=I7h_Gab0duA42{ST}8V<9on@o5adK;Lj4$TmL;iTZRlaNcE zF1&6LTv;hka~iWF8};~H>r~tMthOl-2An0f&eCUPY+h! z>c3ZOHlMoCRY`(}DnQqY19eBIViuA`HhKm_r5I4{dR+8rdB$SfS*>Oa_D7-8&b&W) z{U@*guX)YGD-Hakf-SLEya527J(Uu_PrqBYLI0@RzhO7R`d`NX9R>ex{Ae#A{?quM b!LVoiJE4HE2JwIY3-8{k*?V1uzi)p7q~E=A diff --git a/base_bank_account_number_unique/README.rst b/base_bank_account_number_unique/README.rst index d5dd3f29..9c3dc231 100644 --- a/base_bank_account_number_unique/README.rst +++ b/base_bank_account_number_unique/README.rst @@ -1,20 +1,35 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 + Unique bank account numbers =========================== -It can be desirable to be able to rely on a bank account number identifying exactly one partner. This module allows you to enforce this, so that an account number is unique in the system. +It can be desirable to be able to rely on a bank account number identifying +exactly one partner. This module allows you to enforce this, so that an +account number is unique in the system. Installation ============ -During installation, the module checks if your bank account numbers are unique already. If this is not the case, you won't be able to install the module until duplicates are fixed. +During installation, the module checks if your bank account numbers are +unique already. If this is not the case, you won't be able to install the +module until duplicates are fixed. -The error message only shows the first few duplicates, in order to find all of them, use the following statement:: +The error message only shows the first few duplicates, in order to find all +of them, use the following statement:: - with res_partner_bank_sanitized as (select id, acc_number, regexp_replace(acc_number, '\W+', '', 'g') acc_number_sanitized from res_partner_bank), - res_partner_bank_sanitized_grouped as (select array_agg(id) ids, acc_number_sanitized, count(*) amount from res_partner_bank_sanitized group by acc_number_sanitized) - select * from res_partner_bank_sanitized_grouped where amount > 1; + with res_partner_bank_sanitized as ( + select + id, acc_number, + regexp_replace(acc_number, '\W+', '', 'g') acc_number_sanitized + from res_partner_bank + ), + res_partner_bank_sanitized_grouped as ( + select + array_agg(id) ids, acc_number_sanitized, count(*) amount + from res_partner_bank_sanitized group by acc_number_sanitized + ) + select * from res_partner_bank_sanitized_grouped where amount > 1; Bug Tracker =========== diff --git a/base_bank_account_number_unique/__openerp__.py b/base_bank_account_number_unique/__openerp__.py index 9e6f23d5..95a83089 100644 --- a/base_bank_account_number_unique/__openerp__.py +++ b/base_bank_account_number_unique/__openerp__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# This module copyright (C) 2015 Therp BV . +# Copyright (C) 2015 Therp BV . # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -18,16 +18,16 @@ # ############################################################################## { - "name": "Unique bank account numbers", - "version": "8.0.1.0.0", - "author": "Therp BV,Odoo Community Association (OCA)", - "license": "AGPL-3", - "category": "Accounting & Finance", - "summary": "Enforce uniqueness on bank accounts", - "depends": [ + 'name': 'Unique bank account numbers', + 'version': '8.0.1.0.1', + 'author': 'Therp BV, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'category': 'Banking addons', + 'summary': 'Enforce uniqueness on bank accounts', + 'depends': [ 'account_bank_statement_import', ], - "post_init_hook": "post_init_hook", - "auto_install": False, - "installable": True, + 'post_init_hook': 'post_init_hook', + 'auto_install': False, + 'installable': True, } diff --git a/base_bank_account_number_unique/hooks.py b/base_bank_account_number_unique/hooks.py index 8bcdca36..a8fdb763 100644 --- a/base_bank_account_number_unique/hooks.py +++ b/base_bank_account_number_unique/hooks.py @@ -17,11 +17,12 @@ # along with this program. If not, see . # ############################################################################## -from openerp import _, SUPERUSER_ID, exceptions +from openerp import _, SUPERUSER_ID +from openerp.exceptions import Warning as UserError def post_init_hook(cr, pool): - '''check if your constraint was actually inserted, raise otherwise''' + """check if your constraint was actually inserted, raise otherwise""" if not pool['ir.model.constraint'].search(cr, SUPERUSER_ID, [ ('name', '=', 'res_partner_bank_unique_number'), ('model.model', '=', 'res.partner.bank'), @@ -51,4 +52,4 @@ def post_init_hook(cr, pool): max_account_numbers, '\n'.join(duplicates), max_account_numbers, ) - raise exceptions.Warning(message) + raise UserError(message) diff --git a/base_bank_account_number_unique/tests/test_base_bank_account_number_unique.py b/base_bank_account_number_unique/tests/test_base_bank_account_number_unique.py index de36ea9f..0c87638f 100644 --- a/base_bank_account_number_unique/tests/test_base_bank_account_number_unique.py +++ b/base_bank_account_number_unique/tests/test_base_bank_account_number_unique.py @@ -18,7 +18,7 @@ # ############################################################################## from openerp.tests.common import TransactionCase -from openerp import exceptions +from openerp.exceptions import Warning as UserError from ..hooks import post_init_hook @@ -38,5 +38,5 @@ class TestBaseBankAccountNumberUnique(TransactionCase): 'acc_number': 'BE 1234 567 890', 'state': 'bank', }) - with self.assertRaises(exceptions.Warning): + with self.assertRaises(UserError): post_init_hook(self.cr, self.registry) From f36e24838aa1ed02a2abb9cc5557d4cac4453f22 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sun, 25 Oct 2015 11:09:03 +0100 Subject: [PATCH 4/4] [FIX] Some finetuning of version numbers and #pylint comments. --- account_bank_statement_import/__init__.py | 2 +- .../models/account_bank_statement_import.py | 1 - account_bank_statement_import_camt/__openerp__.py | 2 +- account_bank_statement_import_mt940_nl_ing/__openerp__.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/account_bank_statement_import/__init__.py b/account_bank_statement_import/__init__.py index 4213b8b1..a0fdc10f 100644 --- a/account_bank_statement_import/__init__.py +++ b/account_bank_statement_import/__init__.py @@ -1,2 +1,2 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- from . import models diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index a9e07f1d..479c78b0 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/account_bank_statement_import/models/account_bank_statement_import.py @@ -30,7 +30,6 @@ class AccountBankStatementLine(models.Model): class AccountBankStatementImport(models.TransientModel): """Extend model account.bank.statement.""" - # pylint: disable=too-many-public-methods _name = 'account.bank.statement.import' _description = 'Import Bank Statement' diff --git a/account_bank_statement_import_camt/__openerp__.py b/account_bank_statement_import_camt/__openerp__.py index d54abd61..f4aff843 100644 --- a/account_bank_statement_import_camt/__openerp__.py +++ b/account_bank_statement_import_camt/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'CAMT Format Bank Statements Import', - 'version': '8.0.1.0.4', + 'version': '8.0.0.4.0', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_mt940_nl_ing/__openerp__.py b/account_bank_statement_import_mt940_nl_ing/__openerp__.py index 6cad8a5c..3866a996 100644 --- a/account_bank_statement_import_mt940_nl_ing/__openerp__.py +++ b/account_bank_statement_import_mt940_nl_ing/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'MT940 IBAN ING Format Bank Statements Import', - 'version': '8.0.1.0.4', + 'version': '8.0.0.4.0', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import',