Ejemplo 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))
                           ])
Ejemplo 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)),
         ],
     )
Ejemplo 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))
                        ])
Ejemplo 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))
                           ])
Ejemplo 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)))])
Ejemplo 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")
Ejemplo n.º 8
0
def test_amount():
    assert ("$10.00" == Amount(
        Decimal("10.001"),
        "$").format()), "Formats to 2 points precision by default"
    assert ("10.00 USD" == Amount(
        Decimal(10), "USD").format()), "Longer commodity names come after"
    assert ("-$10.00" == Amount(Decimal(10), "$",
                                reverse=True).format()), "Reverse flag works."
    assert ('10.00 "ABC123"' == Amount(
        Decimal(10), "ABC123").format()), "Currencies with numbers are quoted"
    assert ('10.00 "A BC"' == Amount(
        Decimal(10), "A BC").format()), "Currencies with whitespace are quoted"
    assert "$10.001" == Amount(Decimal("10.001"), "$", unlimited=True).format()
Ejemplo n.º 9
0
 def test_amount(self):
     self.assertEqual("$10.00",
                      Amount(Decimal("10.001"), "$").format(),
                      "Formats to 2 points precision by default")
     self.assertEqual("10.00 USD",
                      Amount(Decimal(10), "USD").format(),
                      "Longer commodity names come after")
     self.assertEqual("-$10.00",
                      Amount(Decimal(10), "$", reverse=True).format(),
                      "Reverse flag works.")
     self.assertEqual("10.00 \"ABC123\"",
                      Amount(Decimal(10), "ABC123").format(),
                      "Currencies with numbers are quoted")
     self.assertEqual("10.00 \"A BC\"",
                      Amount(Decimal(10), "A BC").format(),
                      "Currencies with whitespace are quoted")
     self.assertEqual(
         "$10.001",
         Amount(Decimal("10.001"), "$", unlimited=True).format())
Ejemplo n.º 10
0
 def test_format(self):
     self.assertRegexpMatches(
         Posting("Foo", Amount(Decimal("10.00"), "$")).format(indent=2),
         r'^  Foo.*$')
Ejemplo n.º 11
0
def test_mk_amount_alternate():
    converter = PaypalAlternateConverter(None)
    row = {"Currency": "USD", "Amount": "12.34"}
    assert converter.mk_amount(row) == Amount(Decimal("12.34"), "USD")
Ejemplo n.º 12
0
 def test_mk_amount(self):
     converter = PaypalAlternateConverter(None)
     row = {"Currency": "USD", "Amount": "12.34"}
     self.assertEqual(converter.mk_amount(row),
                      Amount(Decimal('12.34'), "USD"))