X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger%2FFormatter%2FBeancount.pm;h=8cdcb1c8c4cccfa3fdca9ef4ae19db2480097eac;hb=50b191bba1443cafa2fab882ef51f94136272166;hp=7e3f7852bba326f7213d7c592c4fe47938f6c659;hpb=8feecd3de0d3293f8a26c05fc880415aee283e12;p=chaz%2Fhomebank2ledger diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index 7e3f785..8cdcb1c 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -11,7 +11,7 @@ use Scalar::Util qw(looks_like_number); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.006'; # VERSION +our $VERSION = '0.009'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -117,7 +117,7 @@ sub _format_transaction { my $date = $transaction->{date}; my $status = $transaction->{status}; my $payee = $transaction->{payee} || ''; - my $memo = $transaction->{memo} || ''; + my $memo = $transaction->{note} // $transaction->{memo} // ''; my @postings = @{$transaction->{postings}}; my @out; @@ -165,9 +165,10 @@ sub _format_transaction { push @line, ' '; if (defined $posting->{amount}) { push @line, $self->_format_amount($posting->{amount}, $posting->{commodity}); - my $lot_price = $posting->{lot_price}; - my $lot_date = $posting->{lot_date}; - my $lot_ref = $posting->{lot_ref}; + my $lot = $posting->{lot} || {}; + my $lot_price = $lot->{price} // $posting->{lot_price}; + my $lot_date = $lot->{date} // $posting->{lot_date}; + my $lot_ref = $lot->{ref} // $posting->{lot_ref}; if ($lot_price || $lot_date || $lot_ref) { push @line, ' {', join(', ', @@ -223,9 +224,13 @@ sub _format_amount { my $format = "\% .$commodity->{frac}f"; my ($whole, $fraction) = split(/\./, sprintf($format, $amount)); + $fraction ||= 0; # beancount doesn't support different notations - my $num = join('.', commify($whole), $fraction); + my $num = commify($whole); + if ($commodity->{frac}) { + $num .= ".$fraction"; + } $num = "$num $commodity->{iso}"; @@ -297,11 +302,11 @@ App::HomeBank2Ledger::Formatter::Beancount - Beancount formatter =head1 VERSION -version 0.006 +version 0.009 =head1 DESCRIPTION -This is a formatter for L. +This is a formatter for L. =head1 METHODS