From 59e27cd17e0fb069fddf420a61ef51a96be09fa6 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 25 Jun 2015 15:09:32 +0200 Subject: [PATCH] [UPD] adapt to upstream changes --- .../models/account_bank_statement_import.py | 23 +++++---------- .../tests/test_save_file.py | 28 +++++++++++-------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/account_bank_statement_import_save_file/models/account_bank_statement_import.py b/account_bank_statement_import_save_file/models/account_bank_statement_import.py index 9ef8d1b..3e3ab9d 100644 --- a/account_bank_statement_import_save_file/models/account_bank_statement_import.py +++ b/account_bank_statement_import_save_file/models/account_bank_statement_import.py @@ -27,25 +27,16 @@ class AccountBankStatementImport(models.TransientModel): _inherit = 'account.bank.statement.import' @api.model - def _import_statement(self, statement): - (statement_id, notifications) = \ - super(AccountBankStatementImport, self)._import_statement( - statement) - if statement_id: - # get raw file data from the stack - def get_data_file(frame): - if 'data_file' in frame.f_locals: - return frame.f_locals['data_file'] - if frame.f_back: - return get_data_file(frame.f_back) - return None - data_file = get_data_file(inspect.currentframe()) - self.env['account.bank.statement'].browse([statement_id]).write({ + def _import_file(self, data_file): + (statement_ids, notifications) = \ + super(AccountBankStatementImport, self)._import_file(data_file) + if statement_ids: + self.env['account.bank.statement'].browse(statement_ids).write({ 'import_file': self.env['ir.attachment'].create( self._create_import_file_attachment_data( - data_file, statement_id, notifications)).id, + data_file, statement_ids[0], notifications)).id, }) - return (statement_id, notifications) + return (statement_ids, notifications) @api.model def _create_import_file_attachment_data(self, data_file, statement_id, diff --git a/account_bank_statement_import_save_file/tests/test_save_file.py b/account_bank_statement_import_save_file/tests/test_save_file.py index dca847c..7e5b186 100644 --- a/account_bank_statement_import_save_file/tests/test_save_file.py +++ b/account_bank_statement_import_save_file/tests/test_save_file.py @@ -31,18 +31,20 @@ class HelloWorldParser(models.TransientModel): @api.model def _parse_file(self, data_file): - return [{ - 'currency_code': 'EUR', - 'account_number': acc_number, - 'name': '000000123', - 'date': '2013-06-26', - 'transactions': [{ - 'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01', + return ( + 'EUR', + acc_number, + [{ + 'name': '000000123', 'date': '2013-06-26', - 'amount': 42, - 'unique_import_id': 'hello', + 'transactions': [{ + 'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01', + 'date': '2013-06-26', + 'amount': 42, + 'unique_import_id': 'hello', + }], }], - }] + ) class TestSaveFile(TransactionCase): @@ -60,7 +62,11 @@ class TestSaveFile(TransactionCase): if not journal_id: account = import_wizard._create_bank_account(acc_number) journal_id = self.env['account.journal']\ - .search([('currency.name', '=', 'EUR')]).ids[0] + .search([ + '|', + ('currency.name', '=', 'EUR'), + ('currency', '=', False) + ]).ids[0] account.journal_id = journal_id action = import_wizard.with_context(journal_id=journal_id)\ .create({'data_file': base64.b64encode('hello world')})\