]> Dogcows Code - chaz/homebank2ledger/commitdiff
Version 0.004
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 18 Jun 2019 05:28:31 +0000 (23:28 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 18 Jun 2019 05:28:31 +0000 (23:28 -0600)
13 files changed:
Changes
META.json
META.yml
Makefile.PL
README
bin/homebank2ledger
lib/App/HomeBank2Ledger.pm
lib/App/HomeBank2Ledger/Formatter.pm
lib/App/HomeBank2Ledger/Formatter/Beancount.pm
lib/App/HomeBank2Ledger/Formatter/Ledger.pm
lib/App/HomeBank2Ledger/Ledger.pm
lib/App/HomeBank2Ledger/Util.pm
lib/File/HomeBank.pm

diff --git a/Changes b/Changes
index 86e07009d17a3974b8878c5265f88a5e4f3c1866..24f288fbfaf9774be3626f8de8c1abfa2f68f142 100644 (file)
--- 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
index 6d75c9b089aab05695df2d3ad8643587c6c3c15f..277ec80be6548e33ddf5f1ef0eca713da3f67b94 100644 (file)
--- a/META.json
+++ b/META.json
    "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",
          "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"
index 5dd56d2d08e90c099a61bf2432fb3845fc671519..863d993e2d6c987f53112f98357ab4643ac15091 100644 (file)
--- 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'
index 694d8d6591bb237ff1fc46b596b6e9e2b73e74c5..115a98f5bc92cef942bf9c5500318f3687aa54e8 100644 (file)
@@ -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 df13783dbd13724aa29c5acb0216faaaa8a818c8..8ee36730b196ad08f0a75eba0f98fc1a8594d834 100644 (file)
--- 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
index 53a3d6f7ab1a08c5c603b258b2fd5b7c5d4b6100..bc5b00754e4c4c16cc14fddf3b3b90df9d5142d4 100644 (file)
@@ -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<homebank2ledger> tries to come
index 655ba9b7b9059a482735d685ca6924842d537892..5a61f7d5369df135de452f8c5a44ab49876164b9 100644 (file)
@@ -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
 
index 97c320b841a938c6eeefdc8252c686132de91f38..94ee0eccecd5b9c2d1b26491f52252311f3b5c49 100644 (file)
@@ -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
 
index a91cb6a4b0ec2dcff0e9ce2fce073b0e40160534..73fd7a248bfe69af3118ab40e3a392dfc5b07abf 100644 (file)
@@ -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
 
index f9abb48050da1fb97040c93086f47f3416fe960f..8bb52473d6025ff5849d5af72f79de4988ecea7e 100644 (file)
@@ -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
 
index b17a38b4049b7ca4914b07d0ce6fd31f68baa2e4..d61dceea555e4df8f34572a1425701fc5c457710 100644 (file)
@@ -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
 
index c3939d677e6adee98b989664f1ab2e03907a981d..0be4dd3c5114b10911c6a0197ce5f4794b5e91ac 100644 (file)
@@ -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
 
index 4718448eece9a020622df082ffed5d27b769b828..4f38a309477bd4e27223800da7d1ebe222d18e10 100644 (file)
@@ -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
 
This page took 0.045088 seconds and 4 git commands to generate.