Ejemplo n.º 1
0
class McardTestCase(TestCase):
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        Variable(key='GL_ACCOUNTS_PAYABLE', value='3000').save()
        # Create accounts required to generate expense transactions
        Account(id='3000', path="GL_ACCOUNTS_PAYABLE", display_name="GL_ACCOUNTS_PAYABLE").save()
        Account(id='3021', path="mastercard", display_name="Mastercard").save()

        Counterparty(id='mastercard', name="Test C/P").save()


    def test_get_gl_transactions_happy_path(self):

        cp = Counterparty(id='test_cp', name="Test C/P")
        cp.save()

        trans = CreditCardTrans(company=self.default_company,
                                trans_date=datetime.date(2015,1,1),
                                type='sale',
                                amount='100',
                                counterparty=cp)

        transactions = trans.get_gl_transactions()
        self.assertEqual(len(transactions), 1)
Ejemplo n.º 2
0
class NominalTestCase(TestCase):
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        # Create accounts required to generate expense transactions
        
        Variable(key='DEFAULT_COMPANY_ID', value='TEST').save()

    def test_get_gl_transactions_happy_path(self):
        nom_trans = NominalTransaction(id='98765',company=self.default_company, date=datetime.date(2015,1,1))
        
        debit = Account(id='7000', path='capital.opexp.retearnings.debit', display_name='7000')
        credit = Account(id='7010', path='capital.opexp.retearnings.credit', display_name='7010')
        debit.save()
        credit.save()

        cp = Counterparty(id='test_cp', name="Test C/P")
        cp.save()
        
        debit_line = NominalTranLine(transaction_id=nom_trans.id, account=debit, amount='123.4', counterparty=cp)
        debit_line.save()
        nom_trans.nominaltranline_set.add(debit_line)

        credit_line = NominalTranLine(transaction_id=nom_trans.id, account=credit, amount='-123.4', counterparty=cp)
        credit_line.save()
        nom_trans.nominaltranline_set.add(credit_line)

        transactions = nom_trans.get_gl_transactions()
        
        self.assertEqual(len(transactions), 1)
        self.assertEqual(len(transactions[0]['lines']), 2)
Ejemplo n.º 3
0
class TrialBalanceTestCase(TestCase):
  def setUp(self):
    self.default_company = Company(name='TEST_COMPANY', id='TEST')
    self.default_company.save()

    Account(id='1001', path='test.one', display_name='TestOne', role='asset').save()
    Account(id='1002', path='test.two', display_name='TestTwo', role='expense').save()
    Account(id='1003', path='test.three', display_name='TestThree', role='liability').save()

  def test_trial_balance_happy_path(self):
    # setup mock strategy
    mock_strategy = mock.create_autospec(QueryManagerStrategy, instance=True)
    mock_strategy.account_balances_for_dates.return_value = {
      'balance': {
        '1001': 11.00,
        '1002': 22.00,
        '1003': 33.00
      }
    }

    # create trial_balance
    trial_balance = TrialBalance('TEST')
    trial_balance.set_gl_strategy(mock_strategy)

    # run calc
    result = trial_balance.calcs()

    # test calls
    mock_strategy.account_balances_for_dates.assert_called_once_with(
      company_id='TEST',
      account_ids=['1001', '1002', '1003'],
      # TODO: remove hardcoded start date
      dates={'balance': {'start': datetime.date(2013, 1, 1), 'end': None}},
      with_counterparties=None,
      excl_interco=False,
      excl_contra=None,
      with_tags=None,
      excl_tags=None
    )

    # test result
    self.assertEqual(result[0]['label'], '1001: TestOne')
    self.assertEqual(result[0]['Credits']['text'], 0.0)
    self.assertEqual(result[0]['Debits']['text'], 11.0)

    self.assertEqual(result[1]['label'], '1002: TestTwo')
    self.assertEqual(result[1]['Credits']['text'], 0.0)
    self.assertEqual(result[1]['Debits']['text'], 22.0)

    self.assertEqual(result[2]['label'], '1003: TestThree')
    self.assertEqual(result[2]['Credits']['text'], -33.0)
    self.assertEqual(result[2]['Debits']['text'], 0.0)

    self.assertEqual(result[3]['label'], 'Totals')
    self.assertEqual(result[3]['Credits']['text'], -33.0)
    self.assertEqual(result[3]['Debits']['text'], 33.0)
Ejemplo n.º 4
0
    def setUp(self):
        self.default_company = Company(name='TEST_COMPANY', id='TEST')
        self.default_company.save()

        Account(id='1001',
                path='test.one',
                display_name='TestOne',
                role='asset').save()
        Account(id='1002',
                path='test.two',
                display_name='TestTwo',
                role='expense').save()
        Account(id='1003',
                path='test.three',
                display_name='TestThree',
                role='liability').save()
Ejemplo n.º 5
0
  def setUp(self):
    self.default_company = Company(name='TEST_COMPANY', id='TEST')
    self.default_company.save()

    Account(id='1001', path='test.one', display_name='TestOne', role='asset').save()
    Account(id='1002', path='test.two', display_name='TestTwo', role='expense').save()
    Account(id='1003', path='test.three', display_name='TestThree', role='liability').save()
Ejemplo n.º 6
0
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        # Create accounts required to generate expense transactions
        
        Variable(key='DEFAULT_COMPANY_ID', value='TEST').save()
Ejemplo n.º 7
0
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        Variable(key='GL_ACCOUNTS_PAYABLE', value='3000').save()
        # Create accounts required to generate expense transactions
        Account(id='3000', path="GL_ACCOUNTS_PAYABLE", display_name="GL_ACCOUNTS_PAYABLE").save()
        Account(id='3021', path="mastercard", display_name="Mastercard").save()

        Counterparty(id='mastercard', name="Test C/P").save()
Ejemplo n.º 8
0
class CashflowTestCase(TestCase):
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        # Create accounts required to generate expense transactions
        self.ap = Account(id="3000", path="AP", display_name="AP")
        self.chk = Account(id="1001", path="CHECKING1", display_name="CHECKING1")

        self.ap.save()
        self.chk.save()

        self.cp1 = Counterparty(id="jpmc", name="Test C/P")
        self.cp1.save()

        self.cp2 = Counterparty(id="test_cp", name="Test C/P")
        self.cp2.save()
        ExternalAccount(
            company=self.default_company, gl_account=self.chk, counterparty=self.cp1, label="CHK", name="Checking"
        ).save()

    def test_get_gl_transactions_checking(self):
        trans = Cashflow(
            ext_account=ExternalAccount.objects.get(label="CHK"),
            post_date=datetime.date(2015, 1, 1),
            description="test",
            trans_type=Account.objects.get(id="3000"),
            amount="100.2",
            counterparty=Counterparty.objects.get(id="test_cp"),
        )

        transactions = trans.get_gl_transactions()
        self.assertEqual(len(transactions), 1)
        lines = transactions[0]["lines"]
        self.assertEqual(len(lines), 2)

        self.assertEqual(set([(self.chk, 100.2, self.cp1), (self.ap, -100.2, self.cp2)]), set(lines))
Ejemplo n.º 9
0
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        Variable(key='GL_ACCOUNTS_PAYABLE', value='3000').save()
        Variable(key='GL_PREPAID_EXP', value='1250').save()
        Variable(key='GL_ACCRUED_LIAB', value='3110').save()

        # Create accounts required to generate expense transactions
        Account(id='3000', path="GL_ACCOUNTS_PAYABLE", display_name="GL_ACCOUNTS_PAYABLE").save()
        Account(id='1250', path="GL_PREPAID_EXP", display_name="GL_PREPAID_EXP").save()
        Account(id='3110', path="GL_ACCRUED_LIAB", display_name="GL_ACCRUED_LIAB").save()
        Account(id='7890', path="EXPENSE.TEST", display_name="Expense Test").save()

        Counterparty(id='testcp1', name="test1").save()
Ejemplo n.º 10
0
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        # Create accounts required to generate expense transactions
        self.ap = Account(id="3000", path="AP", display_name="AP")
        self.chk = Account(id="1001", path="CHECKING1", display_name="CHECKING1")

        self.ap.save()
        self.chk.save()

        self.cp1 = Counterparty(id="jpmc", name="Test C/P")
        self.cp1.save()

        self.cp2 = Counterparty(id="test_cp", name="Test C/P")
        self.cp2.save()
        ExternalAccount(
            company=self.default_company, gl_account=self.chk, counterparty=self.cp1, label="CHK", name="Checking"
        ).save()
Ejemplo n.º 11
0
class ActivityTestCase(TestCase):
    def setUp(self):
        self.default_company = Company(name='TEST_COMPANY', id='TEST')
        self.default_company.save()

        Account(id='1001',
                path='test.one',
                display_name='TestOne',
                role='asset').save()
        Account(id='1002',
                path='test.two',
                display_name='TestTwo',
                role='expense').save()
        Account(id='1003',
                path='test.three',
                display_name='TestThree',
                role='liability').save()

    def test_activity_happy_path(self):
        # setup mock strategy
        mock_strategy = mock.create_autospec(QueryManagerStrategy,
                                             instance=True)
        mock_strategy.account_balances_for_dates.return_value = {
            'end of 2014': {
                '1001': 10.00,
                '1002': 0.00,
                '1003': 24.00
            },
            'chg in 2015': {
                '1001': 100.00,
                '1002': -1.00,
                '1003': 20.00
            },
            'end of 2015': {
                '1001': 110.00,
                '1002': -1.00,
                '1003': 44.00
            }
        }

        # create activity
        activity = AccountActivity('TEST')
        #activity.columns = {'end of 2014': '2014-12-31', u'chg in 2015': u'2015', u'end of 2015': '2015-12-31'}
        activity.config_fromtag('2015Annual')
        activity.set_gl_strategy(mock_strategy)

        # run calc
        result = activity.calcs()

        # test calls
        mock_strategy.account_balances_for_dates.assert_called_once_with(
            company_id='TEST',
            account_ids=['1001', '1002', '1003'],
            # TODO: remove hardcoded start date
            dates={
                'end of 2014': {
                    'start': datetime.date(2013, 1, 1),
                    'end': datetime.date(2014, 12, 31)
                },
                'chg in 2015': {
                    'start': datetime.date(2015, 1, 1),
                    'end': datetime.date(2015, 12, 31)
                },
                'end of 2015': {
                    'start': datetime.date(2013, 1, 1),
                    'end': datetime.date(2015, 12, 31)
                },
            },
            with_counterparties=None,
            excl_interco=False,
            excl_contra=None,
            with_tags=None,
            excl_tags=None)

        # test result
        self.assertEqual(result[0]['label'], '1001: TestOne')
        self.assertEqual(result[0]['end of 2014']['text'], 10.0)
        self.assertEqual(result[0]['chg in 2015']['text'], 100.0)
        self.assertEqual(result[0]['end of 2015']['text'], 110.0)

        self.assertEqual(result[1]['label'], '1002: TestTwo')
        self.assertEqual(result[1]['end of 2014']['text'], 0.0)
        self.assertEqual(result[1]['chg in 2015']['text'], -1.0)
        self.assertEqual(result[1]['end of 2015']['text'], -1.0)

        self.assertEqual(result[2]['label'], '1003: TestThree')
        self.assertEqual(result[2]['end of 2014']['text'], 24.0)
        self.assertEqual(result[2]['chg in 2015']['text'], 20.0)
        self.assertEqual(result[2]['end of 2015']['text'], 44.0)
Ejemplo n.º 12
0
class ActivityTestCase(TestCase):
  def setUp(self):
    self.default_company = Company(name='TEST_COMPANY', id='TEST')
    self.default_company.save()

    Account(id='1001', path='test.one', display_name='TestOne', role='asset').save()
    Account(id='1002', path='test.two', display_name='TestTwo', role='expense').save()
    Account(id='1003', path='test.three', display_name='TestThree', role='liability').save()

  def test_activity_happy_path(self):
    # setup mock strategy
    mock_strategy = mock.create_autospec(QueryManagerStrategy, instance=True)
    mock_strategy.account_balances_for_dates.return_value = {
      'end of 2014': {
        '1001': 10.00,
        '1002': 0.00,
        '1003': 24.00
      },
       'chg in 2015': {
        '1001': 100.00,
        '1002': -1.00,
        '1003': 20.00
       }, 
       'end of 2015': {
        '1001': 110.00,
        '1002': -1.00,
        '1003': 44.00
      }
    }

    # create activity
    activity = AccountActivity('TEST')
    #activity.columns = {'end of 2014': '2014-12-31', u'chg in 2015': u'2015', u'end of 2015': '2015-12-31'}
    activity.config_fromtag('2015Annual')
    activity.set_gl_strategy(mock_strategy)

    # run calc
    result = activity.calcs()

    # test calls
    mock_strategy.account_balances_for_dates.assert_called_once_with(
      company_id='TEST',
      account_ids=['1001', '1002', '1003'],
      # TODO: remove hardcoded start date
      dates={'end of 2014': {'start': datetime.date(2013, 1, 1), 'end': datetime.date(2014,12,31)},
            'chg in 2015': {'start': datetime.date(2015, 1, 1), 'end': datetime.date(2015,12,31)},
            'end of 2015': {'start': datetime.date(2013, 1, 1), 'end': datetime.date(2015,12,31)},
      },
      with_counterparties=None,
      excl_interco=False,
      excl_contra=None,
      with_tags=None,
      excl_tags=None
    )

    # test result
    self.assertEqual(result[0]['label'], '1001: TestOne')
    self.assertEqual(result[0]['end of 2014']['text'], 10.0)
    self.assertEqual(result[0]['chg in 2015']['text'], 100.0)
    self.assertEqual(result[0]['end of 2015']['text'], 110.0)

    self.assertEqual(result[1]['label'], '1002: TestTwo')
    self.assertEqual(result[1]['end of 2014']['text'], 0.0)
    self.assertEqual(result[1]['chg in 2015']['text'], -1.0)
    self.assertEqual(result[1]['end of 2015']['text'], -1.0)

    self.assertEqual(result[2]['label'], '1003: TestThree')
    self.assertEqual(result[2]['end of 2014']['text'], 24.0)
    self.assertEqual(result[2]['chg in 2015']['text'], 20.0)
    self.assertEqual(result[2]['end of 2015']['text'], 44.0)

    
Ejemplo n.º 13
0
class ExpenseTestCase(TestCase):
    def setUp(self):
        # Create a company for the expense
        self.default_company = Company(name="TEST_COMPANY", id="TEST")
        self.default_company.save()

        Variable(key='GL_ACCOUNTS_PAYABLE', value='3000').save()
        Variable(key='GL_PREPAID_EXP', value='1250').save()
        Variable(key='GL_ACCRUED_LIAB', value='3110').save()

        # Create accounts required to generate expense transactions
        Account(id='3000', path="GL_ACCOUNTS_PAYABLE", display_name="GL_ACCOUNTS_PAYABLE").save()
        Account(id='1250', path="GL_PREPAID_EXP", display_name="GL_PREPAID_EXP").save()
        Account(id='3110', path="GL_ACCRUED_LIAB", display_name="GL_ACCRUED_LIAB").save()
        Account(id='7890', path="EXPENSE.TEST", display_name="Expense Test").save()

        Counterparty(id='testcp1', name="test1").save()



    def test_get_gl_transactions_happy_path(self):
        expense = Expense(company=self.default_company,
                          amount='123.45',
                          account_id='7890',
                          counterparty_id='testcp1')

        transactions = expense.get_gl_transactions()

        self.assertEqual(len(transactions), 1)
        lines = set((l[0].id, l[1], l[2].id) for l in transactions[0]['lines'])
        self.assertEqual(len(lines), 2)

        should_be = [('7890', Decimal('123.45'), 'testcp1'),
                     ('3000', Decimal('-123.45'), 'testcp1')]

        self.assertEqual(set(should_be), set(lines))


    def test_get_gl_transactions_multiperiod_small(self):
        expense = Expense(company=self.default_company,
                          amount='123.45',
                          account_id='7890',
                          start_date=datetime.date(2015,1,1),
                          end_date=datetime.date(2015,10,1),
                          counterparty_id='testcp1')

        transactions = expense.get_gl_transactions()

        self.assertEqual(len(transactions), 1)
        lines = set((l[0].id, l[1], l[2].id) for l in transactions[0]['lines'])
        self.assertEqual(len(lines), 2)

        should_be = [('7890', Decimal('123.45'), 'testcp1'),
                     ('3000', Decimal('-123.45'), 'testcp1')]

        self.assertEqual(set(should_be), set(lines))


    def test_get_gl_transactions_multiperiod_exp_at_end(self):
        expense = Expense(company=self.default_company,
                          amount=Decimal('1230.45'),
                          account_id='7890',
                          start_date=datetime.date(2015,1,1),
                          end_date=datetime.date(2015,10,1),
                          expense_date=datetime.date(2015,10,1),
                          counterparty_id='testcp1')

        transactions = expense.get_gl_transactions()

        self.assertEqual(len(transactions), 2)
        lines = set((l[0].id, l[1], l[2].id) for l in transactions[0]['lines'])
        self.assertEqual(len(lines), 4)

        should_be = [('7890', Decimal('1230.45'), 'testcp1'),
                     ('3000', Decimal('-1230.45'), 'testcp1'),
                     ('3110', Decimal('-1230.45'), 'testcp1'),
                     ('7890', Decimal('1230.45'), 'testcp1')]

        self.assertEqual(set(should_be), set(lines))


    def test_get_gl_transactions_multiperiod_exp_at_start(self):
        expense = Expense(company=self.default_company,
                          amount=Decimal('1230.45'),
                          account_id='7890',
                          start_date=datetime.date(2015,1,1),
                          end_date=datetime.date(2015,10,1),
                          expense_date=datetime.date(2015,1,1),
                          counterparty_id='testcp1')
        transactions = expense.get_gl_transactions()

        self.assertEqual(len(transactions), 2)
        lines_0 = set((l[0].id, l[1], l[2].id) for l in transactions[0]['lines'])
        lines_1 = set((l[0].id, l[1], l[2].id) for l in transactions[1]['lines'])
        lines = lines_0 + lines_1
        self.assertEqual(len(lines), 4)

        should_be = [('1250', Decimal('1230.45'), 'testcp1'),
                     ('3000', Decimal('-1230.45'), 'testcp1'),
                     ('1250', Decimal('-1230.45'), 'testcp1'),
                     ('7890', Decimal('1230.45'), 'testcp1')]
        
        self.assertEqual(set(should_be), set(lines))
Ejemplo n.º 14
0
class TrialBalanceTestCase(TestCase):
    def setUp(self):
        self.default_company = Company(name='TEST_COMPANY', id='TEST')
        self.default_company.save()

        Account(id='1001',
                path='test.one',
                display_name='TestOne',
                role='asset').save()
        Account(id='1002',
                path='test.two',
                display_name='TestTwo',
                role='expense').save()
        Account(id='1003',
                path='test.three',
                display_name='TestThree',
                role='liability').save()

    def test_trial_balance_happy_path(self):
        # setup mock strategy
        mock_strategy = mock.create_autospec(QueryManagerStrategy,
                                             instance=True)
        mock_strategy.account_balances_for_dates.return_value = {
            'balance': {
                '1001': 11.00,
                '1002': 22.00,
                '1003': 33.00
            }
        }

        # create trial_balance
        trial_balance = TrialBalance('TEST')
        trial_balance.set_gl_strategy(mock_strategy)

        # run calc
        result = trial_balance.calcs()

        # test calls
        mock_strategy.account_balances_for_dates.assert_called_once_with(
            company_id='TEST',
            account_ids=['1001', '1002', '1003'],
            # TODO: remove hardcoded start date
            dates={
                'balance': {
                    'start': datetime.date(2013, 1, 1),
                    'end': None
                }
            },
            with_counterparties=None,
            excl_interco=False,
            excl_contra=None,
            with_tags=None,
            excl_tags=None)

        # test result
        self.assertEqual(result[0]['label'], '1001: TestOne')
        self.assertEqual(result[0]['Credits']['text'], 0.0)
        self.assertEqual(result[0]['Debits']['text'], 11.0)

        self.assertEqual(result[1]['label'], '1002: TestTwo')
        self.assertEqual(result[1]['Credits']['text'], 0.0)
        self.assertEqual(result[1]['Debits']['text'], 22.0)

        self.assertEqual(result[2]['label'], '1003: TestThree')
        self.assertEqual(result[2]['Credits']['text'], -33.0)
        self.assertEqual(result[2]['Debits']['text'], 0.0)

        self.assertEqual(result[3]['label'], 'Totals')
        self.assertEqual(result[3]['Credits']['text'], -33.0)
        self.assertEqual(result[3]['Debits']['text'], 33.0)