Permalink
Browse files

Hacked some parts to get it to work with the newest Skandiabanken for…

…mat and AceMoney Lite. (I am not familiar with Python, so don't expect clean code :))
  • Loading branch information...
1 parent 14a9ecf commit 6ed8d35ee3a79bbf676afdc8a4099d6d36395511 @MauriceS committed Mar 12, 2012
Showing with 28 additions and 1 deletion.
  1. +28 −1 sb2qif.py
View
@@ -48,6 +48,8 @@ class QIFFeil(Exception): pass
class qifskriver:
transaksjonstyper = {'E':[], 'I':[]}
+ openingbalance = 0
+ openingbalancedate = ""
filkart = {}
gammelformat = False # i 2008 (?) endret Skandiabanken cvs-formatet fra 8 til 7 kolonner
@@ -56,7 +58,7 @@ class qifskriver:
balanseFormat = """!Type:Bank
D%(aar)s-01-01
POpening Balance
-T0.00
+T%(openingbalance)s
CX
L[konto%(konto)s]
^
@@ -105,6 +107,10 @@ def konverter(self, tilfil=None):
if self.skrivBalanse: # skriv balanse
for konto in self.filkart.keys():
for aar in self.filkart[konto].keys():
+ openingbalance = self.openingbalance
+ self.filkart[konto][aar][openingbalance] = {}
+ openingbalancedate = self.openingbalancedate
+ self.filkart[konto][aar][openingbalancedate] = {}
self.filkart[konto][aar]['buf'].seek(0)
til.write(self.balanseFormat % locals())
til.write(self.filkart[konto][aar]['buf'].read())
@@ -175,6 +181,8 @@ def _konv(self, innfil, utfil, modus='csv'):
f = file(innfil)
topp = f.readline()
skilletegn = self._analyser_skilletegn(topp)
+ f.readline()
+ header = f.readline()
for linje in f:
#BOKF�INGSDATO";"RENTEDATO";"BRUKSDATO";"ARKIVREFERANSE";"TYPE";"TEKST";"UT FRA KONTO";"INN P�KON
#"2005-05-09";"2005-05-09";"09.05.2005";"93070628";"Overfrsel";"UTLBET; ID 9710022000266641";245,73;
@@ -187,6 +195,13 @@ def _konv(self, innfil, utfil, modus='csv'):
if linje.endswith("%s\r\n" % skilletegn):
linje = linje[0:len(linje)-len("%s\r\n" % skilletegn)]
+ if linje.endswith("%s\n" % skilletegn):
+ linje = linje[0:len(linje)-len("%s\n" % skilletegn)]
+
+ #skip blank lines
+ if not linje.strip():
+ continue
+
try:
if self.gammelformat:
bokdato, rentedato, bruksdato, ref, _type, tekst, ut, inn = \
@@ -199,6 +214,11 @@ def _konv(self, innfil, utfil, modus='csv'):
print e
raise TolkeFeil(linje) ## TODO NBNBN XXXX
+ if 'INNGÅENDE SALDO' in tekst.upper():
+ self.openingbalance = self._penger(inn.strip())
+ self.openingbalancedate = ""
+ continue
+
d = {}
d['aar'], d['mnd'], d['dag'] = self._strip(bokdato).split('-') # YYYY-MM-DD
dato = self.datoFormat % d
@@ -282,12 +302,19 @@ def _id(self, dato, tekst):
def _strip(self, s):
s = s.strip()
+ s = s.strip('"')
if s[-1] in ('"', "'"): s = s[:-1]
if not s: return ""
if s[0] == "*":
try: s = s[1:]
except IndexError: return ""
s = s.replace(":", "-") # kmymoney skiller kategorier med kolon, så fjern dem
+ s = s.replace("ø", "oe")
+ s = s.replace("Ø", "OE")
+ s = s.replace("Å", "AA")
+ s = s.replace("å", "aa")
+ s = s.replace("Æ", "AE")
+ s = s.replace("æ", "ae")
return s

0 comments on commit 6ed8d35

Please sign in to comment.