beancount-financial-statement


Namebeancount-financial-statement JSON
Version 0.8.5 PyPI version JSON
download
home_pagehttps://github.com/e7h4n/beancount-financial-statement
SummaryA report generator for beancount financial statement.
upload_time2024-02-26 04:14:14
maintainer
docs_urlNone
authore7h4n
requires_python>=3.6, <4
license
keywords beancount financial statement
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Beancount 财报

[![Build and Publish - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/build.yml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/build.yml)
[![Lint - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/lint.yaml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/lint.yaml)
[![Coverage Status](https://coveralls.io/repos/github/e7h4n/beancount-financial-statement/badge.svg?branch=master)](https://coveralls.io/github/e7h4n/beancount-financial-statement?branch=master)
[![Code scanning - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/codeql-analysis.yml)
[![PyPI version](https://badge.fury.io/py/beancount-financial-statement.svg)](https://badge.fury.io/py/beancount-financial-statement)

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

## Demo

![Balance Sheet](/example/balance_sheet.png)

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

```bash
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
```

## 安装

```bash
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 文件的位置:

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

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

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

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

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

例如:

```beancount
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` 这项所有者权益的计算。

再看一个负债的例子:

```beancount
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` 的计算。

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

在账本开头设置:

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

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

4. 执行命令

```bash
bean-statement --year 2021 --month 8 --beancount YOUR_LEDGER_FILE_PATH
```

## 如何贡献代码

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

```bash
$ 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 在本地快速开始一个开发环境:
```bash
git clone https://github.com/e7h4n/beancount-financial-statement
cd beancount-financial-statement
python3 -m venv .
. bin/activate
pip install -e '.[test]'
```

## Todo

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

## License

MIT.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/e7h4n/beancount-financial-statement",
    "name": "beancount-financial-statement",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "beancount,financial statement",
    "author": "e7h4n",
    "author_email": "ethan.pw@icloud.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/50/94c4fb52173f038333065805b32395da3f0a74c36d99d4650610977f52e6/beancount-financial-statement-0.8.5.tar.gz",
    "platform": null,
    "description": "# Beancount \u8d22\u62a5\n\n[![Build and Publish - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/build.yml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/build.yml)\n[![Lint - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/lint.yaml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/lint.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/e7h4n/beancount-financial-statement/badge.svg?branch=master)](https://coveralls.io/github/e7h4n/beancount-financial-statement?branch=master)\n[![Code scanning - action](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/e7h4n/beancount-financial-statement/actions/workflows/codeql-analysis.yml)\n[![PyPI version](https://badge.fury.io/py/beancount-financial-statement.svg)](https://badge.fury.io/py/beancount-financial-statement)\n\n\u4e00\u4e2a\u7ed9\u4e2a\u4eba\u7528\u7684\u8d22\u62a5\u5de5\u5177\uff0c\u5206\u6790 beancount \u8d26\u672c\uff0c\u81ea\u52a8\u751f\u6210\u8d44\u4ea7\u8d1f\u503a\u8868\u3002\n\n## Demo\n\n![Balance Sheet](/example/balance_sheet.png)\n\n\u53ef\u4ee5 clone \u8fd9\u4e2a\u4ed3\u5e93\u91cd\u73b0\u8fd9\u4e2a\u62a5\u544a:\n\n```bash\ngit clone https://github.com/e7h4n/beancount-financial-statement\ncd beancount-financial-statement\npython3 -m venv .\n. bin/activate\npip3 install .\nbean-statement --year 2021 --month 8 --beancount example/main.bean > /tmp/report.html\nopen /tmp/report.html\n```\n\n## \u5b89\u88c5\n\n```bash\npip install beancount-financial-statement\n```\n\n\u5b89\u88c5\u540e\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4 `bean-statement` \u6765\u4f7f\u7528\u3002\n\n## \u5982\u4f55\u4f7f\u7528\n\n1. \u521b\u5efa\u4e00\u4e2a\u989d\u5916\u7684 layout.txt \u6587\u4ef6\u6765\u63a7\u5236\u8d44\u4ea7\u8d1f\u503a\u8868\u4e2d\u5404\u4e2a\u9879\u76ee\u7684\u987a\u5e8f\u3002\n\n\u4f8b\u5982:\n\n```\nAssets:Current assets:Cash and cash equivalent\nAssets:Current assets:Short-term investment\nAssets:Current assets:Account receivables\nAssets:Non-current assets:Stock and index fund\nAssets:Non-current assets:Equipments\nAssets:Non-current assets:Real estate\nLiabilities:Current liabilities:Credit card\nLiabilities:Current liabilities:Account payable\nLiabilities:Non-current liabilities:Loan\nEquity:Current equity:Current assets\nEquity:Current equity:Current liabilities\nEquity:Non-current equity:Non-current assets\nEquity:Non-current equity:Non-current liabilities\n```\n\n\u540c\u65f6\u5728\u8d26\u672c\u5f00\u5934\u8bbe\u7f6e layout \u6587\u4ef6\u7684\u4f4d\u7f6e:\n\n```beancount\n1970-01-01 custom \"finance-statement-option\" \"balance_sheet_layout\" \"layout.txt\"\n```\n\nbalance_sheet_layout \u662f\u76f8\u5bf9\u4e8e\u8d26\u672c\u4e3b\u6587\u4ef6\u7684\u8def\u5f84\u3002\n\n\u8fd9\u6837\u7684 layout \u4f1a\u8ba9\u8d44\u4ea7\u8d1f\u503a\u8868\u4ece\u4e0a\u5230\u4e0b\u5206\u522b\u662f\u8d44\u4ea7\u3001\u8d1f\u503a\u548c\u6240\u6709\u8005\u6743\u76ca\u3002\n\nLayout \u4e2d\u7684\u6bcf\u4e00\u9879\uff0c\u90fd\u53ef\u4ee5\u5728\u8d26\u672c\u4e2d\u901a\u8fc7 `balance_sheet_category` \u548c `equity_category` \u6765\u6307\u5b9a\u3002\n\n2. \u5728\u8d26\u672c\u4e2d\u7ed9\u6240\u6709\u7684 Assets \u548c Liabilities \u8bbe\u7f6e\u7c7b\u522b\u3002\n\n\u4f8b\u5982:\n\n```beancount\n2019-01-01 open Assets:US:BofA\n  balance_sheet_category: \"Assets:Current assets:Cash and cash equivalent\"\n  equity_category: \"Equity:Current equity:Current assets\"\n```\n\n\u4ee5\u4e0a\u8fd9\u4e2a\u4f8b\u5b50\u7684\u610f\u601d\u662f\uff0c\u5c06 `Assets:US:BofA` \u8fd9\u9879\u8d44\u4ea7\uff0c\u8ba1\u5165 `Assets:Current assets:Cash and cash equivalent` \u8fd9\u4e00\u5206\u7c7b\u3002\u540c\u65f6\u8fd9\u9879\u8d44\u4ea7\u4f1a\u53c2\u4e0e `Equity:Current equity:Current assets` \u8fd9\u9879\u6240\u6709\u8005\u6743\u76ca\u7684\u8ba1\u7b97\u3002\n\n\u518d\u770b\u4e00\u4e2a\u8d1f\u503a\u7684\u4f8b\u5b50:\n\n```beancount\n1980-05-12 open Liabilities:US:Chase:Slate                      USD\n  balance_sheet_category: \"Liabilities:Current liabilities:Credit card\"\n  equity_category: \"Equity:Current equity:Current liabilities\"\n```\n\n\u8fd9\u4e2a\u4f8b\u5b50\u7684\u610f\u601d\u662f\uff0c\u5c06 `Liabilities:US:Chase:Slate` \u8fd9\u9879\u8d1f\u503a\uff0c\u8ba1\u5165 `Liabilities:Current liabilities:Credit card` \u8fd9\u4e00\u5206\u7c7b\uff0c\u540c\u65f6\u8fd9\u9879\u8d44\u4ea7\u4f1a\u53c2\u4e0e `Equity:Current equity:Current liabilities` \u7684\u8ba1\u7b97\u3002\n\n3. \u5728\u8d26\u672c\u4e2d\u914d\u7f6e\u8d22\u62a5\u6240\u4f7f\u7528\u7684\u8d27\u5e01\u3002\n\n\u5728\u8d26\u672c\u5f00\u5934\u8bbe\u7f6e:\n\n```beancount\n1970-01-01 custom \"finance-statement-option\" \"working_currency\" \"USD\"\n```\n\n\u8fd9\u6837\u4f1a\u628a\u751f\u6210\u7684\u62a5\u8868\u6240\u6709\u7684\u8d27\u5e01\u90fd\u7edf\u4e00\u6210 `working_currency`\u3002\n\n4. \u6267\u884c\u547d\u4ee4\n\n```bash\nbean-statement --year 2021 --month 8 --beancount YOUR_LEDGER_FILE_PATH\n```\n\n## \u5982\u4f55\u8d21\u732e\u4ee3\u7801\n\n\u8fd9\u91cc\u6709\u4e00\u4e9b\u5e38\u7528\u7684 `make` \u547d\u4ee4\uff1a\n\n```bash\n$ make\nSome available commands:\n * test         - Run unit tests and test coverage.\n * code-style   - Check code style (pycodestyle).\n * code-lint    - Check code lints (pyflakes, pyline).\n```\n\n\u53ef\u4ee5\u901a\u8fc7 venv \u5728\u672c\u5730\u5feb\u901f\u5f00\u59cb\u4e00\u4e2a\u5f00\u53d1\u73af\u5883:\n```bash\ngit clone https://github.com/e7h4n/beancount-financial-statement\ncd beancount-financial-statement\npython3 -m venv .\n. bin/activate\npip install -e '.[test]'\n```\n\n## Todo\n\n- [x] \u8d44\u4ea7\u8d1f\u503a\u8868\n - [x] \u6613\u4e8e\u4f7f\u7528\u7684\u547d\u4ee4\u884c\u754c\u9762\n - [ ] \u66f4\u591a\u7684 Test Case\n - [ ] \u5b8c\u5584 Pydoc\n - [ ] \u66f4\u597d\u7684 Code Style\n - [ ] \u66f4\u591a\u7684\u4f8b\u5b50\n- [ ] \u5229\u6da6\u8868\n- [ ] \u73b0\u91d1\u6d41\u91cf\u8868\n\n## License\n\nMIT.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A report generator for beancount financial statement.",
    "version": "0.8.5",
    "project_urls": {
        "Bug Reports": "https://github.com/e7h4n/beancount-financial-statement/issues",
        "Homepage": "https://github.com/e7h4n/beancount-financial-statement",
        "Source": "https://github.com/e7h4n/beancount-financial-statement/"
    },
    "split_keywords": [
        "beancount",
        "financial statement"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad230d062f382d16e82135e4d6b779ae3214df20513aff511bd1cc14cbf3ee6a",
                "md5": "00b6c25aa81f40a93df49d1fd58dea0d",
                "sha256": "b899226e7f2f3ccbe5cdd9acfc32f3ccf57e1a7ed331534998a62b28af74b9f6"
            },
            "downloads": -1,
            "filename": "beancount_financial_statement-0.8.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "00b6c25aa81f40a93df49d1fd58dea0d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6, <4",
            "size": 10652,
            "upload_time": "2024-02-26T04:14:12",
            "upload_time_iso_8601": "2024-02-26T04:14:12.857993Z",
            "url": "https://files.pythonhosted.org/packages/ad/23/0d062f382d16e82135e4d6b779ae3214df20513aff511bd1cc14cbf3ee6a/beancount_financial_statement-0.8.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d25094c4fb52173f038333065805b32395da3f0a74c36d99d4650610977f52e6",
                "md5": "8db35867864b0cd45c6f865829c16b40",
                "sha256": "a03b7b8a49fb5171a1344375f558c59c29b64201a24b6b998ddc1b2ec35b850f"
            },
            "downloads": -1,
            "filename": "beancount-financial-statement-0.8.5.tar.gz",
            "has_sig": false,
            "md5_digest": "8db35867864b0cd45c6f865829c16b40",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 8288,
            "upload_time": "2024-02-26T04:14:14",
            "upload_time_iso_8601": "2024-02-26T04:14:14.520409Z",
            "url": "https://files.pythonhosted.org/packages/d2/50/94c4fb52173f038333065805b32395da3f0a74c36d99d4650610977f52e6/beancount-financial-statement-0.8.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 04:14:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "e7h4n",
    "github_project": "beancount-financial-statement",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "beancount-financial-statement"
}
        
Elapsed time: 0.33125s