diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index b17aded1..da01e6c8 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -54,6 +54,7 @@ class BankStatementImportParser(object): self.balance_end = None self.statement_name = None self.statement_date = None + self.support_multi_statements = False @classmethod def parser_for(cls, parser_name): @@ -163,10 +164,16 @@ class BankStatementImportParser(object): raise Exception(_('No buffer file given.')) self._format(*args, **kwargs) self._pre(*args, **kwargs) - self._parse(*args, **kwargs) - self._validate(*args, **kwargs) - self._post(*args, **kwargs) - return self.result_row_list + if self.support_multi_statements: + while self._parse(*args, **kwargs): + self._validate(*args, **kwargs) + self._post(*args, **kwargs) + yield self.result_row_list + else: + self._parse(*args, **kwargs) + self._validate(*args, **kwargs) + self._post(*args, **kwargs) + yield self.result_row_list def itersubclasses(cls, _seen=None): diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 20e4d700..ba0ad7ea 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -138,20 +138,8 @@ class AccountStatementProfil(Model): vals.update(parser.get_st_vals()) return vals - def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None): - """ - Create a bank statement with the given profile and parser. It will fullfill the bank statement - with the values of the file providen, but will not complete data (like finding the partner, or - the right account). This will be done in a second step with the completion rules. - - :param int/long profile_id: ID of the profile used to import the file - :param filebuffer file_stream: binary of the providen file - :param char: ftype represent the file exstension (csv by default) - :return: ID of the created account.bank.statemĂȘnt - """ - statement_obj = self.pool.get('account.bank.statement') - statement_line_obj = self.pool.get('account.bank.statement.line') - attachment_obj = self.pool.get('ir.attachment') + def multi_statement_import(self, cr, uid, ids, profile_id, file_stream, + ftype="csv", context=None): prof_obj = self.pool.get("account.statement.profile") if not profile_id: raise osv.except_osv(_("No Profile!"), @@ -159,7 +147,29 @@ class AccountStatementProfil(Model): prof = prof_obj.browse(cr, uid, profile_id, context=context) parser = new_bank_statement_parser(prof.import_type, ftype=ftype) - result_row_list = parser.parse(file_stream) + res = [] + for result_row_list in parser.parse(file_stream): + statement_id = self._statement_import(cr, uid, ids, prof, parser, file_stream, ftype=ftype, context=context) + res.append(statement_id) + return res + + def _statement_import(self, cr, uid, ids, prof, parser, file_stream, ftype="csv", context=None): + """ + Create a bank statement with the given profile and parser. It will fullfill the bank statement + with the values of the file providen, but will not complete data (like finding the partner, or + the right account). This will be done in a second step with the completion rules. + + :param profile : The profile used to import the file + :param parser: the parser + :param filebuffer file_stream: binary of the providen file + :param char: ftype represent the file exstension (csv by default) + :return: ID of the created account.bank.statemĂȘnt + """ + statement_obj = self.pool.get('account.bank.statement') + statement_line_obj = self.pool.get('account.bank.statement.line') + attachment_obj = self.pool.get('ir.attachment') + + result_row_list = parser.result_row_list # Check all key are present in account.bank.statement.line!! if not result_row_list: raise osv.except_osv(_("Nothing to import"), diff --git a/account_statement_base_import/wizard/import_statement.py b/account_statement_base_import/wizard/import_statement.py index 260a900e..83fa6ffb 100644 --- a/account_statement_base_import/wizard/import_statement.py +++ b/account_statement_base_import/wizard/import_statement.py @@ -99,7 +99,7 @@ class CreditPartnerStatementImporter(orm.TransientModel): ftype = self._check_extension(importer.file_name) context['file_name'] = importer.file_name sid = self.pool.get( - 'account.statement.profile').statement_import( + 'account.statement.profile').multi_statement_import( cr, uid, False, @@ -112,5 +112,5 @@ class CreditPartnerStatementImporter(orm.TransientModel): action_obj = self.pool.get('ir.actions.act_window') action_id = model_obj.get_object_reference(cr, uid, 'account', 'action_bank_statement_tree')[1] res = action_obj.read(cr, uid, action_id) - res['domain'] = res['domain'][:-1] + ",('id', '=', %d)]" % sid + res['domain'] = res['domain'][:-1] + ",('id', 'in', %s)]" % sid return res