Skip to content

Commit acd8b62

Browse files
authored
Merge pull request #8 from bastidest/feature/depreciation-account
allow custom depreciation expense account
2 parents d6bbf73 + 11ae981 commit acd8b62

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,25 @@ Then this plugin will transform the transaction into:
124124

125125
At last, the balance of the account `Assets:Car:ModelX` is 80000 USD.
126126

127+
To change the depreciation expense account, add the `depreciate_account` meta to the `open` statement of the depreciated asset account:
128+
```beancount
129+
1900-01-01 open Assets:Car:ModelX EUR
130+
depreciate_account: "Expenses:Car:Value"
131+
132+
2022-03-31 * "Tesla" "Model X"
133+
Liababilies:CreditCard:0001 -200000 USD
134+
Assets:Car:ModelX
135+
depreciate: "5 Year /Yearly =80000"
136+
137+
138+
; generated transation
139+
2022-03-31 * "Tesla" "Model X Depreciated(1/5)"
140+
Assets:Car:ModelX -24000 USD
141+
Expenses:Car:Value
142+
143+
; ...
144+
```
145+
127146
### Config string in meta
128147

129148
All settings follow the same rules. These are some examples:

beancount_periodic/depreciate.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Dict, Tuple
2+
3+
import beancount.core.getters
14
from beancount.core import data, account, account_types
25
from beancount.parser import options
36

@@ -7,10 +10,31 @@
710
__plugins__ = ('depreciate',)
811

912

13+
def get_depreciation_account(
14+
accounts_open_close: Dict[str, Tuple[beancount.core.data.Open, beancount.core.data.Close]],
15+
expenses_parent: str,
16+
asset_account: beancount.core.data.Account,
17+
) -> str:
18+
new_account = str.join(
19+
account.sep,
20+
[expenses_parent, 'Depreciation', account.sans_root(asset_account)]
21+
)
22+
23+
asset_account_open_statement = accounts_open_close.get(asset_account, None)[0]
24+
open_meta = asset_account_open_statement.meta
25+
depreciate_account = open_meta.get('depreciate_account', None)
26+
27+
if depreciate_account:
28+
return depreciate_account
29+
30+
return new_account
31+
32+
1033
def depreciate(entries: data.Entries, unused_options_map, config_string=""):
1134
new_entries = []
1235
errors = []
1336
account_types_option = options.get_account_types(unused_options_map)
37+
accounts_open_close = beancount.core.getters.get_account_open_close(entries)
1438
for entry in entries:
1539
if isinstance(entry, data.Transaction):
1640
selected_postings_groups = select_periodic_posting_groups(entry, 'depreciate', errors)
@@ -19,9 +43,11 @@ def depreciate(entries: data.Entries, unused_options_map, config_string=""):
1943
for i, config, config_str in selected_postings:
2044
posting: data.Posting = entry.postings[i]
2145
if account_types.is_account_type(account_types_option.assets, posting.account):
22-
new_account = str.join(account.sep,
23-
[account_types_option.expenses, 'Depreciation',
24-
account.sans_root(posting.account)])
46+
new_account = get_depreciation_account(
47+
accounts_open_close,
48+
account_types_option.expenses,
49+
posting.account
50+
)
2551
else:
2652
continue
2753
new_postings_config.append((config, posting, new_account))

0 commit comments

Comments
 (0)