From 0a2af7f81a0cb07cfefaf9b8595dbd302a3ca282 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Mon, 17 Jun 2019 23:28:31 -0600 Subject: [PATCH] Version 0.004 --- Changes | 11 +++++- META.json | 16 ++++----- META.yml | 16 ++++----- Makefile.PL | 2 +- README | 12 ++----- bin/homebank2ledger | 12 ++----- lib/App/HomeBank2Ledger.pm | 35 ++++++++++++------- lib/App/HomeBank2Ledger/Formatter.pm | 6 ++-- .../HomeBank2Ledger/Formatter/Beancount.pm | 4 +-- lib/App/HomeBank2Ledger/Formatter/Ledger.pm | 4 +-- lib/App/HomeBank2Ledger/Ledger.pm | 4 +-- lib/App/HomeBank2Ledger/Util.pm | 4 +-- lib/File/HomeBank.pm | 4 +-- 13 files changed, 68 insertions(+), 62 deletions(-) diff --git a/Changes b/Changes index 86e0700..24f288f 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,16 @@ Revision history for App-HomeBank2Ledger. +0.004 2019-06-17 23:28:10-06:00 MST7MDT + * Remove --default-account option. Instead the default account(s) can be + customized using the --rename-account option, like this: + + --rename-account='^Expenses:Unknown$=Foo' + --rename-account='^Income:Unknown$=Foo' + + * Remove single use of "yada yada" for perls <5.12. + 0.003 2019-06-13 02:55:59-06:00 MST7MDT - * Fix bug that makes the --version and --help flags broken + * Fix bug that makes the --version and --help flags broken. 0.002 2019-06-12 23:39:32-06:00 MST7MDT * Rename dist diff --git a/META.json b/META.json index 6d75c9b..277ec80 100644 --- a/META.json +++ b/META.json @@ -84,31 +84,31 @@ "provides" : { "App::HomeBank2Ledger" : { "file" : "lib/App/HomeBank2Ledger.pm", - "version" : "0.003" + "version" : "0.004" }, "App::HomeBank2Ledger::Formatter" : { "file" : "lib/App/HomeBank2Ledger/Formatter.pm", - "version" : "0.003" + "version" : "0.004" }, "App::HomeBank2Ledger::Formatter::Beancount" : { "file" : "lib/App/HomeBank2Ledger/Formatter/Beancount.pm", - "version" : "0.003" + "version" : "0.004" }, "App::HomeBank2Ledger::Formatter::Ledger" : { "file" : "lib/App/HomeBank2Ledger/Formatter/Ledger.pm", - "version" : "0.003" + "version" : "0.004" }, "App::HomeBank2Ledger::Ledger" : { "file" : "lib/App/HomeBank2Ledger/Ledger.pm", - "version" : "0.003" + "version" : "0.004" }, "App::HomeBank2Ledger::Util" : { "file" : "lib/App/HomeBank2Ledger/Util.pm", - "version" : "0.003" + "version" : "0.004" }, "File::HomeBank" : { "file" : "lib/File/HomeBank.pm", - "version" : "0.003" + "version" : "0.004" } }, "release_status" : "stable", @@ -123,7 +123,7 @@ "web" : "https://github.com/chazmcgarvey/homebank2ledger" } }, - "version" : "0.003", + "version" : "0.004", "x_authority" : "cpan:CCM", "x_generated_by_perl" : "v5.28.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.08" diff --git a/META.yml b/META.yml index 5dd56d2..863d993 100644 --- a/META.yml +++ b/META.yml @@ -28,25 +28,25 @@ no_index: provides: App::HomeBank2Ledger: file: lib/App/HomeBank2Ledger.pm - version: '0.003' + version: '0.004' App::HomeBank2Ledger::Formatter: file: lib/App/HomeBank2Ledger/Formatter.pm - version: '0.003' + version: '0.004' App::HomeBank2Ledger::Formatter::Beancount: file: lib/App/HomeBank2Ledger/Formatter/Beancount.pm - version: '0.003' + version: '0.004' App::HomeBank2Ledger::Formatter::Ledger: file: lib/App/HomeBank2Ledger/Formatter/Ledger.pm - version: '0.003' + version: '0.004' App::HomeBank2Ledger::Ledger: file: lib/App/HomeBank2Ledger/Ledger.pm - version: '0.003' + version: '0.004' App::HomeBank2Ledger::Util: file: lib/App/HomeBank2Ledger/Util.pm - version: '0.003' + version: '0.004' File::HomeBank: file: lib/File/HomeBank.pm - version: '0.003' + version: '0.004' requires: Carp: '0' Exporter: '0' @@ -65,7 +65,7 @@ resources: bugtracker: https://github.com/chazmcgarvey/homebank2ledger/issues homepage: https://github.com/chazmcgarvey/homebank2ledger repository: https://github.com/chazmcgarvey/homebank2ledger.git -version: '0.003' +version: '0.004' x_authority: cpan:CCM x_generated_by_perl: v5.28.0 x_serialization_backend: 'YAML::Tiny version 1.73' diff --git a/Makefile.PL b/Makefile.PL index 694d8d6..115a98f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -41,7 +41,7 @@ my %WriteMakefileArgs = ( "IPC::Open3" => 0, "Test::More" => 0 }, - "VERSION" => "0.003", + "VERSION" => "0.004", "test" => { "TESTS" => "t/*.t" } diff --git a/README b/README index df13783..8ee3673 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME VERSION - version 0.003 + version 0.004 SYNOPSIS @@ -12,7 +12,7 @@ SYNOPSIS [--version|--help|--manual] [--account-width NUM] [--accounts|--no-accounts] [--payees|--no-payees] [--tags|--no-tags] [--commodities|--no-commodities] - [--opening-date DATE] [--default-account STR] + [--opening-date DATE] [--rename-account STR]... [--exclude-account STR]... DESCRIPTION @@ -140,14 +140,6 @@ OPTIONS Date must be in the form "YYYY-MM-DD". Defaults to the date of the first transaction. - --default-account STR - - Specify the account to use for one-sided transactions (if any). - Defaults to "Expenses:No Category". - - A default account may be necessary because with Ledger all transactions - are double-entry. - --rename-account STR Specifies a mapping for renaming accounts in the output. By default diff --git a/bin/homebank2ledger b/bin/homebank2ledger index 53a3d6f..bc5b007 100644 --- a/bin/homebank2ledger +++ b/bin/homebank2ledger @@ -8,7 +8,7 @@ use strict; use App::HomeBank2Ledger; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION App::HomeBank2Ledger->main(@ARGV); @@ -24,7 +24,7 @@ homebank2ledger - A tool to convert HomeBank files to Ledger format =head1 VERSION -version 0.003 +version 0.004 =head1 SYNOPSIS @@ -32,7 +32,7 @@ version 0.003 [--version|--help|--manual] [--account-width NUM] [--accounts|--no-accounts] [--payees|--no-payees] [--tags|--no-tags] [--commodities|--no-commodities] - [--opening-date DATE] [--default-account STR] + [--opening-date DATE] [--rename-account STR]... [--exclude-account STR]... =head1 DESCRIPTION @@ -167,12 +167,6 @@ needed) to support HomeBank's ability to configure accounts with opening balance Date must be in the form "YYYY-MM-DD". Defaults to the date of the first transaction. -=head2 --default-account STR - -Specify the account to use for one-sided transactions (if any). Defaults to "Expenses:No Category". - -A default account may be necessary because with Ledger all transactions are double-entry. - =head2 --rename-account STR Specifies a mapping for renaming accounts in the output. By default C tries to come diff --git a/lib/App/HomeBank2Ledger.pm b/lib/App/HomeBank2Ledger.pm index 655ba9b..5a61f7d 100644 --- a/lib/App/HomeBank2Ledger.pm +++ b/lib/App/HomeBank2Ledger.pm @@ -11,7 +11,7 @@ use File::HomeBank; use Getopt::Long 2.38 qw(GetOptionsFromArray); use Pod::Usage; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION my %ACCOUNT_TYPES = ( # map HomeBank account types to Ledger accounts bank => 'Assets:Bank', @@ -93,6 +93,9 @@ sub convert_homebank_to_ledger { my $homebank = shift; my $opts = shift || {}; + my $default_account_income = 'Income:Unknown'; + my $default_account_expenses = 'Expenses:Unknown'; + my $ledger = App::HomeBank2Ledger::Ledger->new; my $transactions = $homebank->sorted_transactions; @@ -119,13 +122,17 @@ sub convert_homebank_to_ledger { $item->{excluded} = 1 if $item->{ledger_name} =~ /$re/; } } + while (my ($re, $replacement) = each %{$opts->{rename_accounts}}) { + $default_account_income =~ s/$re/$replacement/; + $default_account_expenses =~ s/$re/$replacement/; + } my $has_initial_balance = grep { $_->{initial} && !$_->{excluded} } @$accounts; if ($opts->{accounts}) { my @accounts = map { $_->{ledger_name} } grep { !$_->{excluded} } @$accounts, @$categories; - push @accounts, $opts->{default_account}; + push @accounts, $default_account_income, $default_account_expenses; push @accounts, $OPENING_BALANCES_ACCOUNT if $has_initial_balance; $ledger->add_accounts(@accounts); @@ -256,10 +263,12 @@ sub convert_homebank_to_ledger { my @categories = split(/\|\|/, $transaction->{split_category} || ''); for (my $i = 0; $amounts[$i]; ++$i) { - my $amount = -$amounts[$i]; - my $category = $homebank->find_category_by_key($categories[$i]); - my $memo = $memos[$i] || ''; - my $other_account = $category ? $category->{ledger_name} : $opts->{default_account}; + my $amount = -$amounts[$i]; + my $category = $homebank->find_category_by_key($categories[$i]); + my $memo = $memos[$i] || ''; + my $other_account = $category ? $category->{ledger_name} + : $amount < 0 ? $default_account_income + : $default_account_expenses; push @postings, { account => $other_account, @@ -273,12 +282,16 @@ sub convert_homebank_to_ledger { } } else { # with or without category - my $category = $homebank->find_category_by_key($transaction->{category}); - my $other_account = $category ? $category->{ledger_name} : $opts->{default_account}; + my $amount = -$transaction->{amount}; + my $category = $homebank->find_category_by_key($transaction->{category}); + my $other_account = $category ? $category->{ledger_name} + : $amount < 0 ? $default_account_income + : $default_account_expenses; + push @postings, { account => $other_account, commodity => $commodities{$account->{currency}}, - amount => -$transaction->{amount}, + amount => $amount, payee => $payee->{name}, memo => $memo, status => $status, @@ -335,7 +348,6 @@ sub parse_args { tags => 1, commodities => 1, opening_date => '', - default_account => 'Expenses:No Category', rename_accounts => {}, exclude_accounts => [], ); @@ -353,7 +365,6 @@ sub parse_args { 'tags!' => \$opts{tags}, 'commodities!' => \$opts{commodities}, 'opening-date=s' => \$opts{opening_date}, - 'default-account=s' => \$opts{default_account}, 'rename-account|r=s' => \%{$opts{rename_accounts}}, 'exclude-account|x=s' => \@{$opts{exclude_accounts}}, ) or pod2usage(-exitval => 1, -verbose => 99, -sections => [qw(SYNOPSIS OPTIONS)]); @@ -382,7 +393,7 @@ App::HomeBank2Ledger - A tool to convert HomeBank files to Ledger format =head1 VERSION -version 0.003 +version 0.004 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Formatter.pm b/lib/App/HomeBank2Ledger/Formatter.pm index 97c320b..94ee0ec 100644 --- a/lib/App/HomeBank2Ledger/Formatter.pm +++ b/lib/App/HomeBank2Ledger/Formatter.pm @@ -9,7 +9,7 @@ use Module::Load; use Module::Pluggable search_path => [__PACKAGE__], sub_name => 'available_formatters'; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION sub _croak { require Carp; Carp::croak(@_) } @@ -36,7 +36,7 @@ sub new { sub format { - ... + die "Unimplemented\n"; } @@ -59,7 +59,7 @@ App::HomeBank2Ledger::Formatter - Abstract class for formatting a ledger =head1 VERSION -version 0.003 +version 0.004 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index a91cb6a..73fd7a2 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -9,7 +9,7 @@ use App::HomeBank2Ledger::Util qw(commify rtrim); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -257,7 +257,7 @@ App::HomeBank2Ledger::Formatter::Beancount - Beancount formatter =head1 VERSION -version 0.003 +version 0.004 =head1 DESCRIPTION diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index f9abb48..8bb5247 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -9,7 +9,7 @@ use App::HomeBank2Ledger::Util qw(commify rtrim); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -215,7 +215,7 @@ App::HomeBank2Ledger::Formatter::Ledger - Ledger formatter =head1 VERSION -version 0.003 +version 0.004 =head1 DESCRIPTION diff --git a/lib/App/HomeBank2Ledger/Ledger.pm b/lib/App/HomeBank2Ledger/Ledger.pm index b17a38b..d61dcee 100644 --- a/lib/App/HomeBank2Ledger/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Ledger.pm @@ -5,7 +5,7 @@ package App::HomeBank2Ledger::Ledger; use warnings; use strict; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION sub new { @@ -63,7 +63,7 @@ App::HomeBank2Ledger::Ledger - Ledger data representation =head1 VERSION -version 0.003 +version 0.004 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Util.pm b/lib/App/HomeBank2Ledger/Util.pm index c3939d6..0be4dd3 100644 --- a/lib/App/HomeBank2Ledger/Util.pm +++ b/lib/App/HomeBank2Ledger/Util.pm @@ -6,7 +6,7 @@ use strict; use Exporter qw(import); -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION our @EXPORT_OK = qw(commify rtrim); @@ -42,7 +42,7 @@ App::HomeBank2Ledger::Util - Miscellaneous utility functions =head1 VERSION -version 0.003 +version 0.004 =head1 FUNCTIONS diff --git a/lib/File/HomeBank.pm b/lib/File/HomeBank.pm index 4718448..4f38a30 100644 --- a/lib/File/HomeBank.pm +++ b/lib/File/HomeBank.pm @@ -12,7 +12,7 @@ use Time::Piece; use XML::Entities; use XML::Parser::Lite; -our $VERSION = '0.003'; # VERSION +our $VERSION = '0.004'; # VERSION our @EXPORT_OK = qw(parse_string parse_file); @@ -487,7 +487,7 @@ File::HomeBank - Parse HomeBank files =head1 VERSION -version 0.003 +version 0.004 =head1 SYNOPSIS -- 2.45.2