Skip to content

Commit

Permalink
tests: most tests pass for #70
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Jan 13, 2024
1 parent fe4bde1 commit 9f36b04
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 72 deletions.
9 changes: 8 additions & 1 deletion abacus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@ def validate(self) -> "Chart":
a = list(self.to_dict().keys())
b = [x[0] for x in self.dict_items()]
if len(a) != len(b):
raise AbacusError(["Chart should not contain duplicate account names.", len(a), len(b), set(b)-set(a)])
raise AbacusError(
[
"Chart should not contain duplicate account names.",
len(a),
len(b),
set(b) - set(a),
]
)
return self

def to_dict(self) -> dict[str, Holder]:
Expand Down
16 changes: 7 additions & 9 deletions abacus/typer_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typer
from typing_extensions import Annotated

from abacus.core import BalanceSheet, IncomeStatement, TrialBalance
from abacus.typer_cli.base import get_chart_path, get_entries_path, get_ledger
from abacus.typer_cli.chart import chart
from abacus.typer_cli.ledger import ledger
Expand All @@ -30,17 +31,14 @@ def callback():

@app.command()
def init():
"""Initialize project files in current folder."""
from abacus.typer_cli.chart import init as chart_init
from abacus.typer_cli.ledger import init as ledger_init

chart_init()
ledger_init()


from abacus.typer_cli.base import get_ledger
from abacus.core import TrialBalance, BalanceSheet, IncomeStatement
# FIXME: add balances command

@app.command()
def report(
balance_sheet: Annotated[
Expand All @@ -55,7 +53,9 @@ def report(
bool,
typer.Option("--trial-balance", "-t", help="Show trial balance."),
] = False,
all_reports: Annotated[bool, typer.Option("--all", help="Show all statements.")] = False,
all_reports: Annotated[
bool, typer.Option("--all", help="Show all statements.")
] = False,
):
"""Show reports."""
from abacus.viewers import print_viewers
Expand All @@ -71,15 +71,13 @@ def report(
b.viewer.use(rename_dict).print()
if income_statement and not all_reports:
i.viewer.use(rename_dict).print()
#if account_balances:
# print(json.dumps(account_balances()))
if all_reports:
tv = t.viewer
bv = b.viewer.use(rename_dict)
iv = i.viewer.use(rename_dict)
print_viewers({}, tv, bv, iv)


if not (trial_balance or balance_sheet or income_statement or all_reports):
sys.exit("No reports selected. Use -t, -b, -i or --all flags.")


@app.command(name="assert")
Expand Down
2 changes: 1 addition & 1 deletion abacus/typer_cli/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def load(
store = LineJSON.load(store_file)
# FIXME: store must be empty for load() command
balances = AccountBalances.load(file)
chart = UserChart.load(chart_file)
chart = UserChart.load(chart_file).chart()
entries = starting_entries(chart, balances)
store.append_many(entries)
print("Posted starting balances to ledger:", entries)
Expand Down
10 changes: 5 additions & 5 deletions abacus/typer_cli/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def post_compound(debits, credits, title, chart_file, store_file):
multiple=True,
help="Credit records for compound entry.",
)
@click.option("--start-file", type=Path, help="Load starting balances from JSON file.")
@click.option("--starting-balances-file", type=Path, help="Load starting balances from JSON file.")
@click.option(
"--strict",
"-s",
Expand All @@ -50,12 +50,12 @@ def post_compound(debits, credits, title, chart_file, store_file):
)
@click.option("--title", "-t", type=str, help="Set transaction description.")
def postx(
title, entry, debit, credit, strict, start_file, chart_file, store_file, verbose
title, entry, debit, credit, strict, starting_balances_file, chart_file, store_file, verbose
):
"""Post accounting entries to ledger."""
if start_file:
print("Loading starting balances from", start_file)
load(start_file, chart_file, store_file)
if starting_balances_file:
print(f"Loading starting balances from {starting_balances_file}...")
load(starting_balances_file, chart_file, store_file)

if not strict:
try:
Expand Down
31 changes: 19 additions & 12 deletions abacus/typer_cli/show.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
from json import dumps
from pathlib import Path
from typing import Optional

import typer
from typing_extensions import Annotated

from abacus.typer_cli.base import get_ledger

A = Annotated[list[str], typer.Option()]

show = typer.Typer(help="Show chart and account information.", add_completion=False)


@show.command()
def chart(json: bool = False):
"""Show chart of accounts."""


@show.command()
def account(name: str, json: bool = False):
def account(name: str):
"""Show account information."""


@show.command()
def trial_balance(json: bool = False):
"""Show trial-balance."""


@show.command()
def balances(all: bool = False, json: bool = True):
def balances(
json: bool = True,
nonzero: bool = False,
chart_file: Optional[Path] = None,
store_file: Optional[Path] = None,
):
"""Show account balances."""
ledger = get_ledger(chart_file, store_file)
if nonzero:
data = ledger.balances.nonzero().data
else:
data = ledger.balances.data
print(dumps(data))
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ grill:

# Run examples in scripts folder (linux)
scripts:
cd scripts/vat && bash -e vat.bat
cd scripts/set && bash -e set.bat
cd scripts/textbook && bash -e joan.bat
cd scripts && bash -ex all.sh
cd scripts/textbook && bash -ex joan.bat
cd scripts/textbook && bash -ex accounting_coach.bat
cd scripts/textbook && bash -ex yazici.bat

# Run all tests on documentation files
boil:
just run ./README.md
just run ./docs/index.md
just run ./docs/quick_start.md
just run ./docs/quick_start.md

# Run code and scripts from markdown file
run MD_FILE:
Expand Down
Empty file removed readme.sh
Empty file.
8 changes: 8 additions & 0 deletions scripts/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bash -ex chart.bat
bash -ex post.bat
bash -ex report.bat
bash -ex set_re.bat
bash -ex vat.bat
bash -ex readme.bat
bash -ex clean.bat

4 changes: 4 additions & 0 deletions scripts/clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bx chart unlink --yes
bx ledger unlink --yes
rm -f starting_balances.json
rm -f start.json
10 changes: 10 additions & 0 deletions scripts/readme.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bx unlink --yes
bx init
bx post --entry asset:cash capital:common_stock 20000 --title "Initial investment"
bx report --balance-sheet
bx show balances --nonzero > start.json
bx ledger unlink --yes
bx ledger init
bx assert cash 0
bx post --starting-balances-file start.json
bx assert cash 20000
File renamed without changes.
4 changes: 0 additions & 4 deletions scripts/set/set.bat

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/set_re.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bx unlink --yes
bx init
bx chart set --retained-earnings-account НераспПрибыль
bx assert НераспПрибыль 0
File renamed without changes.
1 change: 0 additions & 1 deletion scripts/vat/starting_balances.json

This file was deleted.

34 changes: 0 additions & 34 deletions subcommand.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_typer_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def assert_subprocess(command: str, line: Line):
def test_post_zzz():
h = (
HappyLine(
"post --entry asset:cash capital:eq 1000 --credit income:sales 50 --credit liability:vat 10 --debit asset:ar 60 --strict"
"post --entry asset:cash capital:eq 1000 --credit income:sales 50 --credit liability:vat 10 --debit asset:ar 60"
)
.prints("Posted")
.prints("sales")
Expand Down

0 comments on commit 9f36b04

Please sign in to comment.