|
@ -5,15 +5,11 @@ import StringIO |
|
|
|
|
|
|
|
|
from openerp import api, models |
|
|
from openerp import api, models |
|
|
from openerp.tools.translate import _ |
|
|
from openerp.tools.translate import _ |
|
|
from openerp.exceptions import Warning |
|
|
|
|
|
|
|
|
from openerp.exceptions import Warning as UserError |
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
from .ofx import OfxParser, OfxParser_ok |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
from ofxparse import OfxParser as ofxparser |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
_logger.warn("ofxparse not found, OFX parsing disabled.") |
|
|
|
|
|
ofxparser = None |
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountBankStatementImport(models.TransientModel): |
|
|
class AccountBankStatementImport(models.TransientModel): |
|
@ -21,11 +17,12 @@ class AccountBankStatementImport(models.TransientModel): |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
|
def _check_ofx(self, data_file): |
|
|
def _check_ofx(self, data_file): |
|
|
if ofxparser is None: |
|
|
|
|
|
|
|
|
if not OfxParser_ok: |
|
|
return False |
|
|
return False |
|
|
try: |
|
|
try: |
|
|
ofx = ofxparser.parse(StringIO.StringIO(data_file)) |
|
|
|
|
|
except: |
|
|
|
|
|
|
|
|
ofx = OfxParser.parse(StringIO.StringIO(data_file)) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
_logger.debug(e) |
|
|
return False |
|
|
return False |
|
|
return ofx |
|
|
return ofx |
|
|
|
|
|
|
|
@ -64,7 +61,7 @@ class AccountBankStatementImport(models.TransientModel): |
|
|
total_amt += float(transaction.amount) |
|
|
total_amt += float(transaction.amount) |
|
|
transactions.append(vals_line) |
|
|
transactions.append(vals_line) |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
raise Warning(_("The following problem occurred during import. " |
|
|
|
|
|
|
|
|
raise UserError(_("The following problem occurred during import. " |
|
|
"The file might not be valid.\n\n %s" % e.message)) |
|
|
"The file might not be valid.\n\n %s" % e.message)) |
|
|
|
|
|
|
|
|
vals_bank_statement = { |
|
|
vals_bank_statement = { |
|
@ -72,7 +69,7 @@ class AccountBankStatementImport(models.TransientModel): |
|
|
'transactions': transactions, |
|
|
'transactions': transactions, |
|
|
'balance_start': ofx.account.statement.balance, |
|
|
'balance_start': ofx.account.statement.balance, |
|
|
'balance_end_real': |
|
|
'balance_end_real': |
|
|
float(ofx.account.statement.balance) + total_amt, |
|
|
|
|
|
|
|
|
float(ofx.account.statement.balance) + total_amt, |
|
|
} |
|
|
} |
|
|
return ofx.account.statement.currency, ofx.account.number, [ |
|
|
return ofx.account.statement.currency, ofx.account.number, [ |
|
|
vals_bank_statement] |
|
|
vals_bank_statement] |