Ejemplo n.º 1
0
    def test_date_formats(self, filename):
        """\
          Posting,Description,Amount
          11/7/2016,A,2
          12/7/2016,B,3
          13/7/2016,C,4
        """
        file = cache.get_file(filename)
        importer = csv.Importer(
            {
                Col.DATE: 'Posting',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount'
            },
            'Assets:Bank',
            'EUR', [],
            dateutil_kwds={'dayfirst': True})
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2016-07-11 * "A"
            Assets:Bank  2 EUR

          2016-07-12 * "B"
            Assets:Bank  3 EUR

          2016-07-13 * "C"
            Assets:Bank  4 EUR

        """, entries)
Ejemplo n.º 2
0
    def test_categorizer_two_arguments(self, filename):
        """\
          Date,Amount,Payee,Description
          6/2/2020,30.00,"Payee here","Description"
          7/2/2020,-25.00,"Supermarket","Groceries"
        """
        file = cache.get_file(filename)

        def categorizer(txn, row):
            txn = txn._replace(payee=row[2])
            txn.meta['source'] = pformat(row)
            return txn

        importer = csv.Importer(
            {
                Col.DATE: 'Date',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount'
            },
            'Assets:Bank',
            'EUR', ('Date,Amount,Payee,Description'),
            categorizer=categorizer,
            institution='foobar')
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2020-06-02 * "Payee here" "Description"
            source: "['6/2/2020', '30.00', 'Supermarket', 'Groceries']"
            Assets:Bank  30.00 EUR
        
          2020-07-02 * "Supermarket" "Groceries"
            source: "['7/2/2020', '-25.00', 'Supermarket', 'Groceries']"
            Assets:Bank  -25.00 EUR
        """, entries)
Ejemplo n.º 3
0
    def test_zero_balance_produces_assertion(self, filename):
        # pylint: disable=line-too-long
        """\
          Details,Posting Date,"Description",Amount,Type,Balance,Check or Slip #,
          DEBIT,3/18/2016,"Payment to Chafe card ending in 1234 03/18",-2680.89,ACCT_XFER,0,,
        """
        file = cache.get_file(filename)

        importer = csv.Importer(
            {
                Col.DATE: 'Posting Date',
                Col.NARRATION1: 'Description',
                Col.NARRATION2: 'Check or Slip #',
                Col.AMOUNT: 'Amount',
                Col.BALANCE: 'Balance',
                Col.DRCR: 'Details'
            },
            'Assets:Bank',
            'USD', ('Details,Posting Date,"Description",Amount,'
                    'Type,Balance,Check or Slip #,'),
            institution='chafe')
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2016-03-18 * "Payment to Chafe card ending in 1234 03/18"
            Assets:Bank  -2680.89 USD
            
          2016-03-19 balance Assets:Bank                                     0 USD

        """, entries)
Ejemplo n.º 4
0
    def test_column_types(self, filename):
        # pylint: disable=line-too-long
        """\
          Details,Posting Date,"Description",Amount,Type,Balance,Check or Slip #,
          DEBIT,3/18/2016,"Payment to Chafe card ending in 1234 03/18",-2680.89,ACCT_XFER,3409.86,,
          CREDIT,3/15/2016,"EMPLOYER INC    DIRECT DEP                 PPD ID: 1111111111",2590.73,ACH_CREDIT,6090.75,,
          DEBIT,3/14/2016,"INVESTMENT SEC   TRANSFER   A5144608        WEB ID: 1234456789",-150.00,ACH_DEBIT,3500.02,,
          DEBIT,3/6/2016,"ATM WITHDRAWAL                       001234  03/8888 DELANC",-60.00,ATM,3650.02,,
          CREDIT,3/5/2016,"CA STATE         NYSTTAXRFD                 PPD ID: 1111111111",110.00,ACH_CREDIT,3710.02,,
          DEBIT,3/4/2016,"BOOGLE           WALLET     US000NEI9T      WEB ID: C234567890",-1300.00,ACH_DEBIT,3600.02,,
        """
        file = cache.get_file(filename)

        importer = csv.Importer(
            {
                Col.DATE: 'Posting Date',
                Col.NARRATION1: 'Description',
                Col.NARRATION2: 'Check or Slip #',
                Col.AMOUNT: 'Amount',
                Col.BALANCE: 'Balance',
                Col.DRCR: 'Details'
            },
            'Assets:Bank',
            'USD', ('Details,Posting Date,"Description",Amount,'
                    'Type,Balance,Check or Slip #,'),
            institution='chafe')
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2016-03-18 * "Payment to Chafe card ending in 1234 03/18"
            Assets:Bank  -2680.89 USD

          2016-03-15 * "EMPLOYER INC    DIRECT DEP                 PPD ID: 1111111111"
            Assets:Bank  2590.73 USD

          2016-03-14 * "INVESTMENT SEC   TRANSFER   A5144608        WEB ID: 1234456789"
            Assets:Bank  -150.00 USD

          2016-03-06 * "ATM WITHDRAWAL                       001234  03/8888 DELANC"
            Assets:Bank  -60.00 USD

          2016-03-05 * "CA STATE         NYSTTAXRFD                 PPD ID: 1111111111"
            Assets:Bank  110.00 USD

          2016-03-04 * "BOOGLE           WALLET     US000NEI9T      WEB ID: C234567890"
            Assets:Bank  -1300.00 USD

          2016-03-19 balance Assets:Bank                                     3409.86 USD

        """, entries)
Ejemplo n.º 5
0
    def test_explict_encoding_utf8(self, filename):
        """\
          Posting,Description,Amount
          2020/08/08,🍏,2
        """
        file = cache.get_file(filename)
        importer = csv.Importer(
            {
                Col.DATE: 'Posting',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount'
            },
            'Assets:Bank',
            'EUR', [],
            encoding='utf-8')
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2020-08-08 * "🍏"
            Assets:Bank  2 EUR

        """, entries)
Ejemplo n.º 6
0
    def test_categorizer_one_argument(self, filename):
        """\
          Date,Amount,Payee,Description
          6/2/2020,30.00,"Payee here","Description"
          7/2/2020,-25.00,"Supermarket","Groceries"
        """
        file = cache.get_file(filename)

        def categorizer(txn):
            if txn.narration == "Groceries":
                txn.postings.append(
                    data.Posting("Expenses:Groceries", -txn.postings[0].units,
                                 None, None, None, None))

            return txn

        importer = csv.Importer(
            {
                Col.DATE: 'Date',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount'
            },
            'Assets:Bank',
            'EUR', ('Date,Amount,Payee,Description'),
            categorizer=categorizer,
            institution='foobar')
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2020-06-02 * "Description"
            Assets:Bank  30.00 EUR
        
          2020-07-02 * "Groceries"
            Assets:Bank  -25.00 EUR
            Expenses:Groceries  25.00 EUR
        """, entries)
Ejemplo n.º 7
0
    def test_tags(self, filename):
        """\
          Date,Description,Amount,Tag
          2020-07-03,A,2,
          2020-07-03,B,3,foo
        """
        file = cache.get_file(filename)
        importer = csv.Importer(
            {
                Col.DATE: 'Date',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount',
                Col.TAG: 'Tag'
            }, 'Assets:Bank', 'EUR', [])
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2020-07-03 * "A"
            Assets:Bank  2 EUR

          2020-07-03 * "B" #foo
            Assets:Bank  3 EUR
        """, entries)
Ejemplo n.º 8
0
    def test_links(self, filename):
        """\
          Date,Description,Amount,Link
          2020-07-03,A,2,
          2020-07-03,B,3,123
        """
        file = cache.get_file(filename)
        importer = csv.Importer(
            {
                Col.DATE: 'Date',
                Col.NARRATION: 'Description',
                Col.AMOUNT: 'Amount',
                Col.REFERENCE_ID: 'Link'
            }, 'Assets:Bank', 'EUR', [])
        entries = importer.extract(file)
        self.assertEqualEntries(
            r"""

          2020-07-03 * "A"
            Assets:Bank  2 EUR

          2020-07-03 * "B" ^123
            Assets:Bank  3 EUR
        """, entries)
Ejemplo n.º 9
0
    # At this time the txn has only one posting
    try:
        posting1 = txn.postings[0]
    except IndexError:
        return txn

    from importers.beanmaker import mapping_account
    account_name = mapping_account(_debit_account, txn.narration)

    posting2 = posting1._replace(account=account_name, units=-posting1.units)
    # Insert / Append the posting into the transaction
    if posting1.units < posting2.units:
        txn.postings.append(posting2)
    else:
        txn.postings.insert(0, posting2)

    return txn


comm_config = csv.Importer(config=_config_com,
                           account=_default_account_comm,
                           currency=_currency,
                           last4_map={"2987": "优逸白"},
                           categorizer=comm_categorizer)

CONFIG = [
    wechat_config,
    alipay_config,
    comm_config,
]
Ejemplo n.º 10
0
            extra_narration = " TODO"
            if "返现" in txn.narration:
                extra_narration = ""

            txn.postings.append(
                post._replace(
                    account=post.account.replace("Liabilities", "Income"),
                    units=-post.units,
                ))
            if extra_narration:
                txn = txn._replace(narration=txn.narration + extra_narration)
    return txn


CONFIG = [
    csv.Importer(
        {
            # 日期、金额等字段分别叫什么?
            csv.Col.DATE: '记账日期',
            csv.Col.AMOUNT_DEBIT: '交易金额',
            csv.Col.NARRATION1: '交易描述',
            csv.Col.LAST4: '卡号末四位'
        },
        # CSV文件中有哪几列?
        regexps='卡号末四位,记账日期,交易金额,交易描述',
        account="Liabilities:CN:CreditCard:SPDB",
        currency='CNY',
        categorizer=categorizer,
    )
]