示例#1
0
 def test_get_colored_amount(self):
     self.assertEqual("\x1b[0;32m$0.00\x1b[0m", util.get_colored_amount(-0.00000000000000000000001))
     self.assertEqual("\x1b[0;32m$0.00\x1b[0m", util.get_colored_amount(0.00000000000000000000001))
     self.assertEqual("\x1b[0;31m$-3.14\x1b[0m", util.get_colored_amount(-3.14))
     self.assertEqual("\x1b[0;32m$3.14\x1b[0m", util.get_colored_amount(3.14))
     self.assertEqual("\x1b[0;31m$-5.68\x1b[0m", util.get_colored_amount(-5.678))
     self.assertEqual("\x1b[0;32m$5.67\x1b[0m", util.get_colored_amount(5.672))
     self.assertEqual("\x1b[0;32m     $9.99\x1b[0m", util.get_colored_amount(9.99, column_width=10))
示例#2
0
    def list_transactions(self, args=None):
        args = util.parse_args(args)
        if args and args[0].lower() == 'all':
            show_all = True
        else:
            show_all = False

        self.current_listing = {}
        count = 0
        for thing in self.open_transactions:
            if thing.thing_date > self.ending_date \
                    and not show_all \
                    and not thing.is_pending():
                continue

            if not self.current_listing:
                print()  # only print one buffer line at top if items

            count += 1
            self.current_listing[str(count)] = thing
            count_str = '{:-4}.'.format(count)
            print(
                '{number} {date} {amount} {status:1} {payee} '
                '{code:>7}'.format(
                    number=util.get_cyan_text(count_str),
                    date=thing.get_date_string(),
                    code=thing.transaction_code,
                    payee=util.get_cyan_text(
                        thing.payee,
                        column_width=40
                    ),
                    amount=util.get_colored_amount(
                        thing.rec_amount,
                        10
                    ),
                    status=thing.rec_status
                )
            )

        end_date = util.get_cyan_text(
            util.get_date_string(self.ending_date)
        )

        if self.ending_balance is None:
            end_balance = util.get_cyan_text('(not set)')
        else:
            end_balance = util.get_colored_amount(self.ending_balance)

        print(
            '\nending date: {end_date} ending balance: {end_balance} '
            'cleared: {cleared}'.format(
                end_date=end_date,
                end_balance=end_balance,
                cleared=util.get_colored_amount(self.total_cleared)
            )
        )

        if self.ending_balance is not None:
            print('to zero: {}'.format(
                util.get_colored_amount(self.get_zero_candidate())
            ))

        print()