def setUp(self): create_accounts(self) journ5 = posts.Journals(journalstat = posts.Journals.UNPROCESSED,\ extkey='NR501') journ5.add() journ6 = posts.Journals(journalstat = posts.Journals.UNPROCESSED,\ extkey='NR503') journ6.add() gledger.db.session.flush() self.journ5id = journ5.id self.journ5extkey = journ5.extkey self.journ6id = journ6.id self.journ6extkey = journ6.extkey posting_to_journal(journ5) post9 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=journ6.id, postmonth=201609, value_date=datetime.now(), amount=20, debcred='Cr') post9.add() post10 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=journ6.id, postmonth=201609, value_date=datetime.now(), amount=20, debcred='Db') post10.add()
def posting_to_journal(journ2): post3 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=250, debcred='Cr') post3.add() post4 = posts.Postings(accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=230, debcred='Db') post4.add() post5 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("btw (ontvangen)").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=20, debcred='Db') post5.add() return journ2
def test_unbalanced_journal_fails(self): """ When a debit and credit amount is not the same, the journal must be refused! """ journ2 = posts.Journals.get_by_id(self.journ2id) post6 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=230, debcred='Cr') post6.add() post7 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=230, debcred='Db') post7.add() post8 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("btw (ontvangen)").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=20, debcred='Cr') post8.add() gledger.db.session.flush() with self.assertRaises(posts.JournalBalanceError): journ2.post_journal()
def test_create_journal(self): """ Create a journal with its postings """ journ2 = posts.Journals.get_by_id(self.journ2id) post3 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=230, debcred='Cr') post3.add() post4 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=250, debcred='Db') post4.add() post5 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("btw (ontvangen)").id, journals_id=journ2.id, postmonth=201609, value_date=datetime.now(), amount=20, debcred='Cr') post5.add() gledger.db.session.flush() q = gledger.db.session.query(posts.Postings).join(posts.Journals).\ filter(posts.Journals.id==journ2.id) self.assertEqual(q.count(), 3, "Too little postings in journal")
def create_posting_to_kas(instance, posting_amount, postmonth, journal_id): """ Post an amount to kas for test purposes """ postn = posts.Postings(accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=journal_id, postmonth=postmonth, value_date=datetime.now(), amount=posting_amount, debcred='Db') postn.add()
def test_no_post_wo_journal(self): """Inserting posting w/o journal fails """ post2 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, postmonth=201608, value_date=datetime.now(), amount=250, debcred='Cr') post2.add() with self.assertRaises(DatabaseError): gledger.db.session.flush()
def test_posting_no_id_fails(self): """ Making a view for a posting with no id fails """ post12 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=self.journ7id, postmonth=201609, value_date=datetime.now(), amount=12, debcred='Cr') post12.add() with self.assertRaises(ValueError): post12view = postviews.PostingView(post12.id)
def test_post_debcred_invalid(self): """ Posting with invalid debit/credit indicator must be refused """ journ4 = posts.Journals(journalstat=posts.Journals.UNPROCESSED) journ4.add() gledger.db.session.flush() with self.assertRaises(posts.InvalidDebitCreditError): post3 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=journ4.id, postmonth=201609, value_date=datetime.now(), amount=230, debcred='Ct') gledger.db.session.flush()
def test_post_one_posting(self): """ A posting can be inserted """ post1 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, postmonth=201608, value_date=datetime.now(), amount=250, debcred='Cr') journ3 = posts.Journals(journalstat=posts.Journals.UNPROCESSED) journ3.add() journ3.journalpostings.append(post1) post1.add() q = gledger.db.session.query(posts.Postings) self.assertNotEqual(q.count(), 0, 'Posting not inserted')
def test_createview(self): """ Create a view for one posting """ post11 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=self.journ7id, postmonth=201609, value_date=datetime.now(), amount=120, debcred='Cr') post11.add() gledger.db.session.flush() post11view = postviews.PostingView(post11.id) self.assertEqual(post11view.posting.amount, 120, 'Amount in view incorrect')
def test_posting_account(self): """ A postingview contains the account name """ post14 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("kas").id, journals_id=self.journ7id, postmonth=201608, value_date=datetime.now(), amount=5500, debcred='Db') post14.add() gledger.db.session.flush() post14view = postviews.PostingView(post14.id) post14viewdict = post14view.as_dict() self.assertEqual(post14viewdict['account'], 'kas', 'Wrong account in postview')
def test_postingview_as_dict(self): """ A postingview can be returned as a dictionary """ post13 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=self.journ7id, postmonth=201609, value_date=datetime.now(), amount=6500, debcred='Cr') post13.add() gledger.db.session.flush() post13view = postviews.PostingView(post13.id) post13viewdict = post13view.as_dict() self.assertIn("id", post13viewdict, 'No id in posting dictionary') self.assertEqual(post13viewdict['amount'], '65.00', 'Amount incorrect')
def test_read_by_account_month(self): """ Read postings by account and postmonth """ post9 = posts.Postings( accounts_id=accmodel.Accounts.get_by_name("verkopen").id, journals_id=self.journ5id, postmonth=201608, value_date=datetime.now(), amount=20, debcred='Cr') post9.add() gledger.db.session.flush() acc10 = accmodel.Accounts.get_by_name("verkopen") account_postings = \ posts.Postings.postings_for_account(acc10, month='09-2016') self.assertEqual(len(account_postings), 2, 'Incorrect no. of posts for account')