You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. import logging
  3. _logger = logging.getLogger(__name__)
  4. try:
  5. from ofxparse import OfxParser as OfxParserOriginal
  6. OfxParser_ok = True
  7. except ImportError:
  8. _logger.warn("ofxparse not found, OFX parsing disabled.")
  9. OfxParserOriginal = object
  10. OfxParser_ok = False
  11. class OfxParser(OfxParserOriginal):
  12. """ Custom changes in the OFX Parser.
  13. """
  14. @classmethod
  15. def _tagToDecimal(self, tag):
  16. tag.string = tag.string.replace(',', '.')
  17. @classmethod
  18. def parseStatement(cls_, stmt_ofx):
  19. """Amount with ',' replaced by '.' in the following tags :
  20. //LEDGERBAL/BALAMT
  21. """
  22. ledgerbal_tag = stmt_ofx.find('ledgerbal')
  23. if hasattr(ledgerbal_tag, "contents"):
  24. cls_._tagToDecimal(ledgerbal_tag.find('balamt'))
  25. return super(OfxParser, cls_).parseStatement(stmt_ofx)
  26. @classmethod
  27. def parseTransaction(cls_, txn_ofx):
  28. """Amount with ',' replaced by '.' in the following tags :
  29. //TRNAMT
  30. """
  31. cls_._tagToDecimal(txn_ofx.find('trnamt'))
  32. return super(OfxParser, cls_).parseTransaction(txn_ofx)