API reference¶
abacus.core
¶
Core elements of a minimal double-entry accounting system.
Using this module you can:
- create a chart of accounts using
Chart
class, - create
Ledger
fromChart
, - post entries to
Ledger
, - generate trial balance, balance sheet and income statement.
Implemented in this module:
- contra accounts — there can be a
refunds
account that offsetsincome:sales
anddepreciation
account that offsetsasset:ppe
, - multiple entries — debit and credit several accounts in one transaction,
- closing entries — proper closing of accounts at the accounting period end.
Assumptions and simplifications:
- no sub-accounts — there is only one level of account hierarchy in chart
- account names must be globally unique
- no cashflow statement
- one currency
- no checks for account non-negativity
Defining a chart¶
abacus.Chart
dataclass
¶
Chart of accounts.
Example:
chart = Chart(assets=["cash"], capital=["equity"])
Source code in abacus/core.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
abacus.core.Account
dataclass
¶
Source code in abacus/core.py
134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
Entries¶
abacus.core.Entry
dataclass
¶
Double entry with account name to be debited, account name to be credited and transaction amount.
Example:
entry = Entry(debit="cash", credit="equity", amount=20000)
Source code in abacus/core.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
abacus.core.CompoundEntry
dataclass
¶
An entry that affects several accounts at once.
Source code in abacus/core.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
|
to_entries(null_account_name)
¶
Return list of double entries that make up multiple entry. The double entries will correspond to null account.
Source code in abacus/core.py
683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
validate()
¶
Assert sum of debit entries equals sum of credit entries.
Source code in abacus/core.py
676 677 678 679 680 681 |
|
Processing entries¶
abacus.core.TAccount
dataclass
¶
Bases: ABC
T-account will hold amounts on debits and credit side.
Source code in abacus/core.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
balance()
abstractmethod
¶
Return account balance.
Source code in abacus/core.py
164 165 166 |
|
condense()
¶
Create a new account of the same type with only one value as account balance.
Source code in abacus/core.py
176 177 178 |
|
credit(amount)
¶
Add credit amount to account.
Source code in abacus/core.py
160 161 162 |
|
debit(amount)
¶
Add debit amount to account.
Source code in abacus/core.py
156 157 158 |
|
empty()
¶
Create a new empty account of the same type.
Source code in abacus/core.py
180 181 182 |
|
topup(balance)
¶
Add starting balance to a proper side of account.
Source code in abacus/core.py
184 185 186 187 188 189 190 191 |
|
transfer_balance(my_name, dest_name)
abstractmethod
¶
Create an entry that transfers account balance from this account to destination account.
This account name is my_name
and destination account name is dest_name
.
Source code in abacus/core.py
168 169 170 171 172 173 174 |
|
abacus.core.Ledger
¶
Bases: UserDict[str, TAccount]
Source code in abacus/core.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
balances
property
¶
Return account balances.
condense()
¶
Return a new ledger with condensed accounts that hold just one value. Used to avoid copying of ledger data where only account balances are needed.
Source code in abacus/core.py
445 446 447 448 449 450 |
|
new(chart, balances)
classmethod
¶
Create a new ledger from chart, possibly using starting balances.
Source code in abacus/core.py
397 398 399 400 401 402 403 404 |
|
post(debit, credit, amount, title='')
¶
Post to ledger using debit and credit account names and amount.
Source code in abacus/core.py
406 407 408 409 |
|
post_many(entries)
¶
Post several double entries to ledger.
Source code in abacus/core.py
415 416 417 418 419 420 421 422 423 424 425 426 |
|
post_one(entry)
¶
Post one double entry to ledger.
Source code in abacus/core.py
411 412 413 |
|
subset(cls)
¶
Filter ledger by account type.
Source code in abacus/core.py
435 436 437 438 439 440 441 442 443 |
|
abacus.core.Pipeline
¶
A pipeline to accumulate ledger transformations.
Source code in abacus/core.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
|
close_contra(t)
¶
Close contra accounts of type t
.
Source code in abacus/core.py
482 483 484 485 486 487 488 489 |
|
close_first()
¶
Close contra income and contra expense accounts.
Source code in abacus/core.py
511 512 513 514 515 |
|
close_isa_to_re()
¶
Close income summary account to retained earnings account.
Source code in abacus/core.py
501 502 503 504 505 506 507 508 509 |
|
close_last()
¶
Close permanent contra accounts.
Source code in abacus/core.py
524 525 526 527 528 529 |
|
close_second()
¶
Close income and expense accounts to income summary account, then close income summary account to retained earnings.
Source code in abacus/core.py
517 518 519 520 521 522 |
|
close_to_isa()
¶
Close income or expense accounts to income summary account.
Source code in abacus/core.py
491 492 493 494 495 496 497 498 499 |
|
Reports¶
abacus.core.BalanceSheet
dataclass
¶
Bases: Statement
Source code in abacus/core.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
|
abacus.core.IncomeStatement
dataclass
¶
Bases: Statement
Source code in abacus/core.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
|
abacus.core.TrialBalance
¶
Bases: UserDict[str, tuple[Amount, Amount]]
, Statement
Trial balance is a dictionary of account names and their debit-side and credit-side balances.
Source code in abacus/core.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
abacus.core.AccountBalances
¶
Bases: UserDict[str, Amount]
Source code in abacus/core.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
abacus.Report
dataclass
¶
Source code in abacus/core.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|