[FIX] account_bank_statement_import: ofx and qif don't save the uploaded file on the server anymore + data_file is now mandatory in _parse_file()

This commit is contained in:
qdp-odoo
2015-01-16 18:43:09 +01:00
parent a1fac87d25
commit 2ca0f0e5d1
4 changed files with 9 additions and 24 deletions
@@ -70,7 +70,7 @@ class account_bank_statement_import(osv.TransientModel):
'type': 'ir.actions.client',
}
def _parse_file(self, cr, uid, data_file=None, context=None):
def _parse_file(self, cr, uid, data_file, context=None):
""" 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.
This method parses the given file and returns the data required by the bank statement import process, as specified below.
rtype: triplet (if a value can't be retrieved, use None)
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import logging
import os
import StringIO
from openerp.osv import osv
from openerp.tools.translate import _
@@ -28,17 +28,8 @@ class account_bank_statement_import(osv.TransientModel):
return False
return ofx
def _parse_file(self, cr, uid, data_file=None, context=None):
try:
tempfile = open("temp.ofx", "w+")
tempfile.write(data_file)
tempfile.read()
pathname = os.path.dirname('temp.ofx')
path = os.path.join(os.path.abspath(pathname), 'temp.ofx')
except:
raise UserError(_('File handling error.'))
ofx = self._check_ofx(cr, uid, file(path), context=context)
def _parse_file(self, cr, uid, data_file, context=None):
ofx = self._check_ofx(cr, uid, StringIO.StringIO(data_file), context=context)
if not ofx:
return super(account_bank_statement_import, self)._parse_file(cr, uid, data_file, context=context)
@@ -65,7 +56,6 @@ class account_bank_statement_import(osv.TransientModel):
total_amt += float(transaction.amount)
transactions.append(vals_line)
except Exception, e:
os.remove(path)
raise UserError(_("The following problem occurred during import. The file might not be valid.\n\n %s" % e.message))
vals_bank_statement = {
@@ -74,5 +64,4 @@ class account_bank_statement_import(osv.TransientModel):
'balance_start': ofx.account.statement.balance,
'balance_end_real': float(ofx.account.statement.balance) + total_amt,
}
os.remove(path)
return ofx.account.statement.currency, ofx.account.number, [vals_bank_statement]
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import dateutil.parser
from tempfile import TemporaryFile
import StringIO
from openerp.tools.translate import _
from openerp.osv import osv, fields
@@ -23,7 +23,7 @@ class account_bank_statement_import(osv.TransientModel):
}
def _get_journal(self, cr, uid, currency_id, bank_account_id, account_number, context=None):
""" As .QIF format does not allow us to detect the journal, we need to let the user choose it.
""" As .QIF format does not allow us to detect the journal, we need to let the user choose it.
We set it in context before to call super so it's the same as calling the widget from a journal """
if context is None:
context = {}
@@ -36,18 +36,14 @@ class account_bank_statement_import(osv.TransientModel):
def _check_qif(self, cr, uid, data_file, context=None):
return data_file.strip().startswith('!Type:')
def _parse_file(self, cr, uid, data_file=None, context=None):
def _parse_file(self, cr, uid, data_file, context=None):
if not self._check_qif(cr, uid, data_file, context=context):
return super(account_bank_statement_import, self)._parse_file(cr, uid, data_file, context=context)
try:
fileobj = TemporaryFile('wb+')
fileobj.write(data_file)
fileobj.seek(0)
file_data = ""
for line in fileobj.readlines():
for line in StringIO.StringIO(data_file).readlines():
file_data += line
fileobj.close()
if '\r' in file_data:
data_list = file_data.split('\r')
else:
@@ -38,7 +38,7 @@ class account_bank_statement_import(osv.TransientModel):
# Matches the first 24 characters of a CODA file, as defined by the febelfin specifications
return re.match('0{5}\d{9}05[ D] {7}', data_file) != None
def _parse_file(self, cr, uid, data_file=None, context=None):
def _parse_file(self, cr, uid, data_file, context=None):
if not self._check_coda(cr, uid, data_file, context=context):
return super(account_bank_statement_import, self)._parse_file(cr, uid, data_file, context=context)