Skip to content

Commit

Permalink
minimal.py contains code form readme
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Jun 4, 2023
1 parent 5a04add commit 70bc9dc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ journal = (
.close()
)
print(journal.balance_sheet())
# BalanceSheet(
# assets={"cash": 1540, "goods": 50},
# capital={"equity": 1500, "re": 90},
# liabilities={},
# )
# BalanceSheet(assets={'cash': 1350, 'ar': 190, 'goods': 50},
# capital={'equity': 1500, 're': 90},
# liabilities={})
print(journal.income_statement())
# IncomeStatement(income={"sales": 399},
# expenses={"cogs": 250, "sga": 59})
# IncomeStatement(income={'sales': 399},
# expenses={'cogs': 250, 'sga': 59})
```

## What `abacus` is for?
Expand Down
52 changes: 51 additions & 1 deletion minimal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abacus import Chart
from abacus import Chart, BalanceSheet, IncomeStatement

chart = Chart(
assets=["cash", "ar", "goods"],
Expand Down Expand Up @@ -26,3 +26,53 @@
print(journal.income_statement())
# IncomeStatement(income={"sales": 399},
# expenses={"cogs": 250, "sga": 59})

from abacus import Chart, Entry


chart = Chart(
assets=["cash", "receivables", "goods_for_sale"],
expenses=["cogs", "sga"],
equity=["equity"],
retained_earnings_account="re",
liabilities=["divp", "payables"],
income=["sales"],
)

journal = chart.journal()

e1 = Entry(dr="cash", cr="equity", amount=1000) # pay in capital
e2 = Entry(dr="goods_for_sale", cr="cash", amount=250) # acquire goods worth 250
e3 = Entry(cr="goods_for_sale", dr="cogs", amount=200) # sell goods worth 200
e4 = Entry(cr="sales", dr="cash", amount=400) # for 400 in cash
e5 = Entry(cr="cash", dr="sga", amount=50) # administrative expenses
journal = journal.post_many([e1, e2, e3, e4, e5]).close()

from abacus import IncomeStatement

income_statement = journal.income_statement()
assert income_statement == IncomeStatement(
income={"sales": 400}, expenses={"cogs": 200, "sga": 50}
)

from abacus import BalanceSheet

balance_sheet = journal.balance_sheet()
assert balance_sheet == BalanceSheet(
assets={"cash": 1100, "receivables": 0, "goods_for_sale": 50},
capital={"equity": 1000, "re": 150},
liabilities={"divp": 0, "payables": 0},
)

from abacus import RichViewer


rename_dict = {
"re": "Retained earnings",
"divp": "Dividend due",
"cogs": "Cost of goods sold",
"sga": "Selling, general and adm. expenses",
}
rv = RichViewer(rename_dict, width=60)
rv.print(balance_sheet)
rv.print(income_statement)

0 comments on commit 70bc9dc

Please sign in to comment.