Esempio n. 1
0
    def convert(self, row):
        metadata = {
            'Desc.': persian.convert_fa_numbers(row[t['sharh']]),
        }
        amount = int(row[t['mablagh']])
        amount = amount / 10000

        name = persian.convert_fa_numbers(row[t['zinaf']])
        matchNumber = re.findall('(\d+)', name)
        accountNumber = ''
        if matchNumber:
            accountNumber = matchNumber[0]
            name = name.replace(accountNumber, ' ' + accountNumber + ' ')
        metadata['Name'] = name

        fromAccount = self.unknownaccount
        foundAccount = self.accounts.get(str(accountNumber), None)
        payee = name
        if accountNumber != '' and foundAccount:
            fromAccount = foundAccount['account']
            payee = foundAccount['name']

        if accountNumber != '':
            payee = "(" + accountNumber + ") " + payee

        if amount < 0:
            reverse = True
            amount = abs(amount)
        else:
            reverse = False
            amount = abs(amount)
            fromAccount = 'Income:Salary'

        jdatestring = row[t['date']]
        jdate = jdatetime.date(int(jdatestring[:4]), int(jdatestring[5:7]),
                               int(jdatestring[8:]))
        date = jdate.togregorian()
        metadata['Date'] = jdate.isoformat() + ', ' + jdate.j_weekdays_en[
            jdate.weekday()]
        metadata['Time'] = row[t['time']]

        unit = 'kIRT'

        return Transaction(cleared=True,
                           date=date,
                           payee=payee,
                           metadata=metadata,
                           postings=[
                               Posting(account=fromAccount,
                                       amount=Amount(amount,
                                                     unit,
                                                     reverse=not reverse)),
                               Posting(account=self.name,
                                       amount=Amount(amount,
                                                     unit,
                                                     reverse=reverse))
                           ])
Esempio n. 2
0
 def convert(self, row):
     amount = row["Amount"]
     return Transaction(
         date=datetime.datetime.strptime(row["Date"], "%d/%m/%Y"),
         payee=row["Description"].strip(),
         postings=[
             Posting(self.name, Amount(amount, "GBP")),
             Posting(self.unknownaccount, Amount(amount, "GBP", reverse=True)),
         ],
     )
Esempio n. 3
0
 def convert(self, row):
     amount = row['Amount']
     return Transaction(date=datetime.datetime.strptime(
         row['Date'], "%d/%m/%Y"),
                        payee=row['Description'].strip(),
                        postings=[
                            Posting(self.name, Amount(amount, 'GBP')),
                            Posting(self.unknownaccount,
                                    Amount(amount, 'GBP', reverse=True))
                        ])
Esempio n. 4
0
    def convert(self, row):
        desc = persian.convert_fa_numbers(row['enbank'])
        metadata = {'Desc.': desc}
        inputAmount = int(row['3'])
        outputAmount = int(row['4'])
        amount = 0
        reverse = True

        accountNumber = ""
        matchNumber = re.findall('(\d{7,9})', desc)
        if matchNumber:
            accountNumber = int(matchNumber[0])

        fromAccount = self.unknownaccount
        foundAccount = self.accounts.get(str(accountNumber), None)
        payee = 'Unknown'
        if accountNumber is not '' and foundAccount:
            fromAccount = foundAccount['account']
            payee = foundAccount['name']

        if accountNumber is not '':
            payee = "(" + str(accountNumber) + ") " + payee

        if outputAmount > 0:
            amount = outputAmount / 10000
            reverse = True
        else:
            amount = inputAmount / 10000
            reverse = False
            fromAccount = 'Income:Salary'

        jdatestring = row['1']
        jdate = jdatetime.date(int(jdatestring[0:4]), int(jdatestring[5:7]),
                               int(jdatestring[8:]))
        date = jdate.togregorian()
        metadata['Date'] = jdate.isoformat() + ', ' + jdate.j_weekdays_en[
            jdate.weekday()]
        metadata['Time'] = row['2']

        unit = 'kIRT'

        return Transaction(cleared=True,
                           date=date,
                           payee=payee,
                           metadata=metadata,
                           postings=[
                               Posting(account=fromAccount,
                                       amount=Amount(amount,
                                                     unit,
                                                     reverse=not reverse)),
                               Posting(account=self.name,
                                       amount=Amount(amount,
                                                     unit,
                                                     reverse=reverse))
                           ])
Esempio n. 5
0
 def convert(self, row):
     amount = row['Amount']
     if amount.startswith('-'):
         reverse = True
     else:
         reverse = False
     return Transaction(
         date=datetime.datetime.strptime(row['Date'], "%d/%m/%Y"),
         payee=row['Description'],
         postings=[Posting(self.name, Amount(amount, 'GBP', reverse=reverse)),
                   Posting(self.unknownaccount, Amount(amount, 'GBP', reverse=not(reverse)))])
Esempio n. 6
0
def test_format():
    assert (
        Posting("Foo", Amount(Decimal("10.00"), "$"), metadata={
            "foo": "bar"
        }).format(indent=2) ==
        "  Foo                                                      $10.00\n  ; foo: bar\n"
    )
 def test_format(self):
     self.assertEqualLedgerPosting(
         Posting("Foo",
                 Amount(Decimal("10.00"), "$"),
                 metadata={
                     'foo': 'bar'
                 }).format(indent=2), "  Foo  $10.00\n  ; foo: bar\n")
Esempio n. 8
0
 def test_format(self):
     self.assertRegexpMatches(
         Posting("Foo", Amount(Decimal("10.00"), "$")).format(indent=2),
         r'^  Foo.*$')