[IMP] Give the possibility to parse and import multiple statments

This commit is contained in:
Laurent Mignon (Acsone)
2014-05-05 21:36:31 +02:00
parent 6c84e21644
commit 0960cf0d03
3 changed files with 38 additions and 21 deletions

View File

@@ -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"),