Skip to content

Commit

Permalink
Added ledger in accountant (#66)
Browse files Browse the repository at this point in the history
* Added ledger in accountant

* updated version
  • Loading branch information
sameer-639 authored Apr 15, 2024
1 parent 8196a9b commit d23fac3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pyluca/accountant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import json
from typing import Optional
from pyluca.journal import Journal, JournalEntry
from pyluca.ledger import Ledger


class Accountant:
def __init__(self, journal: Journal, config: dict, key: str):
self.journal = journal
self.config = config
self.key = key
self.ledger = Ledger(journal, config, key)

def enter_journal(
self,
Expand All @@ -25,6 +27,7 @@ def enter_journal(
JournalEntry(len(self.journal.entries), dr_account, amount, 0, date, narration, self.key, event_id))
self.journal.add_entry(
JournalEntry(len(self.journal.entries), cr_account, 0, amount, date, narration, self.key, event_id))
self.ledger.add_entry(dr_account, cr_account, amount, date, narration, event_id)

def record(
self,
Expand Down
20 changes: 8 additions & 12 deletions pyluca/tests/test_accountant.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,20 @@ def test_base(self):
accountant = Accountant(Journal(), account_config, 'person1')
accountant.enter_journal('SAVINGS_BANK', 'SALARY', 20000, datetime(2022, 4, 30), 'April salary')
self.assertEqual(len(accountant.journal.entries), 2)
ledger = Ledger(accountant.journal, accountant.config)
self.assertEqual(ledger.get_account_balance('SAVINGS_BANK'), 20000)
self.assertEqual(ledger.get_account_balance('SALARY'), 20000)
self.assertEqual(len(ledger.get_df()), 2)
self.assertEqual(accountant.ledger.get_account_balance('SAVINGS_BANK'), 20000)
self.assertEqual(accountant.ledger.get_account_balance('SALARY'), 20000)
self.assertEqual(len(accountant.ledger.get_df()), 2)

accountant.enter_journal('MUTUAL_FUNDS', 'SAVINGS_BANK', 10000, datetime(2022, 5, 1), 'ELSS')
ledger = Ledger(accountant.journal, accountant.config)
self.assertEqual(ledger.get_account_balance('SAVINGS_BANK'), 10000)
self.assertEqual(ledger.get_account_balance('MUTUAL_FUNDS'), 10000)
self.assertEqual(accountant.ledger.get_account_balance('SAVINGS_BANK'), 10000)
self.assertEqual(accountant.ledger.get_account_balance('MUTUAL_FUNDS'), 10000)

accountant.enter_journal('LOANS', 'SAVINGS_BANK', 5000, datetime(2022, 5, 2), 'Lend to Pramod')
ledger = Ledger(accountant.journal, accountant.config)
self.assertEqual(ledger.get_account_balance('LOANS'), 5000)
self.assertEqual(ledger.get_account_balance('SAVINGS_BANK'), 5000)
self.assertEqual(accountant.ledger.get_account_balance('LOANS'), 5000)
self.assertEqual(accountant.ledger.get_account_balance('SAVINGS_BANK'), 5000)

accountant.enter_journal('CAR_EMI', 'SAVINGS_BANK', 3000, datetime(2022, 5, 2), 'EMI 3/48')
ledger = Ledger(accountant.journal, accountant.config)
self.assertEqual(ledger.get_account_balance('SAVINGS_BANK'), 2000)
self.assertEqual(accountant.ledger.get_account_balance('SAVINGS_BANK'), 2000)

bal, ledger, acct_type_bal = {}, Ledger(accountant.journal, accountant.config), defaultdict(int)
for acct_name, acct in account_config['accounts'].items():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='pyluca',
version='3.0.0',
version='3.1.0',
author='datasignstech',
author_email='[email protected]',
description='Double entry accounting system',
Expand Down

0 comments on commit d23fac3

Please sign in to comment.