Skip to main content

Beancount 财报

Build and Publish - action Lint - action Coverage Status Code scanning - action PyPI version

一个给个人用的财报工具,分析 beancount 账本,自动生成资产负债表。

Demo

Balance Sheet

可以 clone 这个仓库重现这个报告:

git clone https://github.com/e7h4n/beancount-financial-statement
cd beancount-financial-statement
python3 -m venv .
. bin/activate
pip3 install .
bean-statement --year 2021 --month 8 --beancount example/main.bean > /tmp/report.html
open /tmp/report.html

安装

pip install beancount-financial-statement

安装后可以通过命令 bean-statement 来使用。

如何使用

  1. 创建一个额外的 layout.txt 文件来控制资产负债表中各个项目的顺序。

例如:

Assets:Current assets:Cash and cash equivalent
Assets:Current assets:Short-term investment
Assets:Current assets:Account receivables
Assets:Non-current assets:Stock and index fund
Assets:Non-current assets:Equipments
Assets:Non-current assets:Real estate
Liabilities:Current liabilities:Credit card
Liabilities:Current liabilities:Account payable
Liabilities:Non-current liabilities:Loan
Equity:Current equity:Current assets
Equity:Current equity:Current liabilities
Equity:Non-current equity:Non-current assets
Equity:Non-current equity:Non-current liabilities

同时在账本开头设置 layout 文件的位置:

1970-01-01 custom "finance-statement-option" "balance_sheet_layout" "layout.txt"

balance_sheet_layout 是相对于账本主文件的路径。

这样的 layout 会让资产负债表从上到下分别是资产、负债和所有者权益。

Layout 中的每一项,都可以在账本中通过 balance_sheet_category 和 equity_category 来指定。

  1. 在账本中给所有的 Assets 和 Liabilities 设置类别。

例如:

2019-01-01 open Assets:US:BofA
  balance_sheet_category: "Assets:Current assets:Cash and cash equivalent"
  equity_category: "Equity:Current equity:Current assets"

以上这个例子的意思是,将 Assets:US:BofA 这项资产,计入 Assets:Current assets:Cash and cash equivalent 这一分类。同时这项资产会参与 Equity:Current equity:Current assets 这项所有者权益的计算。

再看一个负债的例子:

1980-05-12 open Liabilities:US:Chase:Slate                      USD
  balance_sheet_category: "Liabilities:Current liabilities:Credit card"
  equity_category: "Equity:Current equity:Current liabilities"

这个例子的意思是,将 Liabilities:US:Chase:Slate 这项负债,计入 Liabilities:Current liabilities:Credit card 这一分类,同时这项资产会参与 Equity:Current equity:Current liabilities 的计算。

  1. 在账本中配置财报所使用的货币。

在账本开头设置:

1970-01-01 custom "finance-statement-option" "working_currency" "USD"

这样会把生成的报表所有的货币都统一成 working_currency。

  1. 执行命令
bean-statement --year 2021 --month 8 --beancount YOUR_LEDGER_FILE_PATH

如何贡献代码

这里有一些常用的 make 命令:

$ make
Some available commands:
 * test         - Run unit tests and test coverage.
 * code-style   - Check code style (pycodestyle).
 * code-lint    - Check code lints (pyflakes, pyline).

可以通过 venv 在本地快速开始一个开发环境:

git clone https://github.com/e7h4n/beancount-financial-statement
cd beancount-financial-statement
python3 -m venv .
. bin/activate
pip install -e '.[test]'

Todo

  • 资产负债表
  • 易于使用的命令行界面
  • 更多的 Test Case
  • 完善 Pydoc
  • 更好的 Code Style
  • 更多的例子
  • 利润表
  • 现金流量表

License

MIT.

Metadata

Release files for beancount-financial-statement 0.8.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beancount-financial-statement 0.8.5
File Size Uploaded Provenance Actions
beancount-financial-statement-0.8.5.tar.gz 8.3 kB Without provenance Details for beancount-financial-statement-0.8.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for beancount-financial-statement 0.8.5
File Interpreter ABI Platform Actions
beancount_financial_statement-0.8.5-py3-none-any.whl Python 3 none any Details for beancount_financial_statement-0.8.5-py3-none-any.whl

Total release size: 18.9 kB

Release files / beancount-financial-statement-0.8.5.tar.gz

Download URL beancount-financial-statement-0.8.5.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a03b7b8a49fb5171a1344375f558c59c29b64201a24b6b998ddc1b2ec35b850f
BLAKE2b-256 checksum
How to use checksums
d25094c4fb52173f038333065805b32395da3f0a74c36d99d4650610977f52e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / beancount_financial_statement-0.8.5-py3-none-any.whl

Download URL beancount_financial_statement-0.8.5-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b899226e7f2f3ccbe5cdd9acfc32f3ccf57e1a7ed331534998a62b28af74b9f6
BLAKE2b-256 checksum
How to use checksums
ad230d062f382d16e82135e4d6b779ae3214df20513aff511bd1cc14cbf3ee6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Security for beancount-financial-statement 0.8.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page