hledger-forecast 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac4e0a16f2b440612fb4596519b02c02d4a88b0d5f9cdb95c0988047a9892c3e
4
- data.tar.gz: 6f9aed952f65c445d965a9b3dd7ccdb25fdb2c300bdee748ffab51b6a5a5056e
3
+ metadata.gz: b5ba12a84909e9d92ac3a9b1b5d977b661131fe6673f8a1c6e73f9ec57d790e2
4
+ data.tar.gz: 8f7f23fde8f640912eacb23982e198d67bfe83671c43eba6357a1cdde9a87528
5
5
  SHA512:
6
- metadata.gz: 40eb12f6238c4cc0f8fc37e85a74a6f4e88fbbd12917b07dfd2d305dd47f0cb09e1c999a343744d5766cb03c1484533e67ae6eb3e7ed6a7c3548f5f177eea55e
7
- data.tar.gz: e09a771caf387bf62d9b09ca58ff59073589edeb0d9cbc3a9523246c31b7172b83869101fe6a020474d501a3b739dbe7a24ac6676a4baafb1380a5fe0c2a84b5
6
+ metadata.gz: 33c532dc9e25ff41c968a1ada59379dbc56a9a0587e2abc4f07acdd10387c88b6f834ec6025dccb44e5ab5f4b3446341e09b947275e540857884728e84b5392a
7
+ data.tar.gz: 918e5be4d90e1bd52a75436ce0ded33a72e49dd29e9d0a112067eddf2b86693a8ac6c21bd027ed2148d28819e5af432e594a063ca28fdcbe14bceeaee335d283
data/README.md CHANGED
@@ -70,6 +70,7 @@ The available options are:
70
70
  -f, --forecast FILE The path to the FORECAST CSV/YML file to generate from
71
71
  -o, --output-file FILE The path to the OUTPUT file to create
72
72
  -t, --transaction FILE The path to the TRANSACTION journal file
73
+ -v, --verbose Don't group transactions by type in the output file
73
74
  --force Force an overwrite of the output file
74
75
  --no-track Don't track any transactions
75
76
  -h, --help Show this help message
@@ -86,6 +87,8 @@ To work with hledger, include the forecast file and use the `--forecast` flag:
86
87
 
87
88
  The command will generate a forecast up to the end of Feb 2024, showing the balance for any asset accounts, overlaying some bank transactions with the forecast journal file. Forecasting in hledger can be complicated so be sure to refer to the [documentation](https://hledger.org/dev/hledger.html) or start a [discussion](https://github.com/olimorris/hledger-forecast/discussions/new?category=q-a).
88
89
 
90
+ If you use the `hledger-ui` tool, it may be helpful to use the `--verbose` flag. This ensures that transactions are not grouped together in the forecast journal file, making descriptions much easier to read.
91
+
89
92
  ### Summarize command
90
93
 
91
94
  As your configuration file grows, it can be helpful to sum up the total amounts and output them to the CLI.
@@ -91,6 +91,11 @@ module HledgerForecast
91
91
  options[:transaction_file] = file
92
92
  end
93
93
 
94
+ opts.on("-v", "--verbose",
95
+ "Don't group transactions by type in the output file") do
96
+ options[:verbose] = true
97
+ end
98
+
94
99
  opts.on("--force",
95
100
  "Force an overwrite of the output file") do
96
101
  options[:force] = true
@@ -13,11 +13,7 @@ module HledgerForecast
13
13
  def generate
14
14
  data.each_value do |blocks|
15
15
  blocks.each do |block|
16
- if block[:type] == "custom"
17
- process_custom_block(block)
18
- else
19
- process_block(block)
20
- end
16
+ process_block(block)
21
17
  end
22
18
  end
23
19
 
@@ -34,30 +30,59 @@ module HledgerForecast
34
30
  @output = []
35
31
  end
36
32
 
37
- def process_custom_block(block)
33
+ def process_block(block)
38
34
  block[:transactions].each do |to, transactions|
39
35
  to = get_header(block[:to], to)
40
36
 
41
- transactions.each do |t|
42
- header = "~ #{t[:frequency]} from #{block[:from]}#{to} * #{t[:description]}\n"
43
- footer = " #{block[:account]}\n\n"
44
- output << { header: header, transactions: write_transactions([t]), footer: footer }
37
+ if block[:type] == "custom"
38
+ process_custom_transactions(block, to, transactions)
39
+ else
40
+ process_standard_transactions(block, to, transactions)
45
41
  end
46
42
  end
47
43
  end
48
44
 
49
- def process_block(block)
50
- block[:transactions].each do |to, transactions|
51
- to = get_header(block[:to], to)
52
- block[:descriptions] = get_descriptions(transactions)
45
+ def process_custom_transactions(block, to, transactions)
46
+ transactions.each do |t|
47
+ frequency = get_periodic_rules(block[:type], t[:frequency])
53
48
 
54
- frequency = get_periodic_rules(block[:type], block[:frequency])
49
+ header = build_header(block, to, frequency, t[:description])
50
+ footer = build_footer(block)
51
+ output << build_transaction(header, [t], footer)
52
+ end
53
+ end
55
54
 
56
- header = "#{frequency} #{block[:from]}#{to} * #{block[:descriptions]}\n"
57
- footer = " #{block[:account]}\n\n"
55
+ def process_standard_transactions(block, to, transactions)
56
+ if @options[:verbose]
57
+ transactions.map do |t|
58
+ # Skip transactions that have been marked as tracked
59
+ next if t[:track]
58
60
 
59
- output << { header: header, transactions: write_transactions(transactions), footer: footer }
61
+ frequency = get_periodic_rules(block[:type], block[:frequency])
62
+ header = build_header(block, to, frequency, t[:description])
63
+ footer = build_footer(block)
64
+ output << build_transaction(header, [t], footer)
65
+ end
66
+ return
60
67
  end
68
+
69
+ block[:descriptions] = get_descriptions(transactions)
70
+ frequency = get_periodic_rules(block[:type], block[:frequency])
71
+ header = build_header(block, to, frequency, block[:descriptions])
72
+ footer = build_footer(block)
73
+ output << build_transaction(header, transactions, footer)
74
+ end
75
+
76
+ def build_header(block, to, frequency, description)
77
+ "#{frequency} #{block[:from]}#{to} * #{description}\n"
78
+ end
79
+
80
+ def build_footer(block)
81
+ " #{block[:account]}\n\n"
82
+ end
83
+
84
+ def build_transaction(header, transactions, footer)
85
+ { header: header, transactions: write_transactions(transactions), footer: footer }
61
86
  end
62
87
 
63
88
  def get_header(block, transaction)
@@ -1,3 +1,3 @@
1
1
  module HledgerForecast
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require_relative '../lib/hledger_forecast'
2
+
3
+ output = <<~JOURNAL
4
+ ~ monthly from 2023-03-01 * Mortgage
5
+ Expenses:Mortgage £2,000.55; Mortgage
6
+ Assets:Bank
7
+
8
+ ~ monthly from 2023-03-01 * Food
9
+ Expenses:Food £100.00 ; Food
10
+ Assets:Bank
11
+
12
+ ~ monthly from 2023-03-01 * Savings
13
+ Assets:Bank £-1,000.00; Savings
14
+ Assets:Savings
15
+
16
+ JOURNAL
17
+
18
+ RSpec.describe 'verbose command' do
19
+ it 'does not group similar type transactions together in the output' do
20
+ generated_journal = './test_output.journal'
21
+ File.delete(generated_journal) if File.exist?(generated_journal)
22
+
23
+ system("./bin/hledger-forecast generate -f ./spec/stubs/forecast.csv -o ./test_output.journal --verbose --force")
24
+
25
+ expect(File.read(generated_journal)).to eq(output)
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hledger-forecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oli Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -145,6 +145,7 @@ files:
145
145
  - spec/stubs/transactions_not_found.journal
146
146
  - spec/summarizer_spec.rb
147
147
  - spec/track_spec.rb
148
+ - spec/verbose_output_spec.rb
148
149
  - spec/yearly_spec.rb
149
150
  homepage: https://github.com/olimorris/hledger-forecast
150
151
  licenses:
@@ -189,4 +190,5 @@ test_files:
189
190
  - spec/stubs/transactions_not_found.journal
190
191
  - spec/summarizer_spec.rb
191
192
  - spec/track_spec.rb
193
+ - spec/verbose_output_spec.rb
192
194
  - spec/yearly_spec.rb