X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger%2FFormatter%2FBeancount.pm;h=f264475aa0819294bdac73fc84587154cfae6fa4;hb=dbe865909f64e75de821e3bffa7d6a8c241eb0fc;hp=748a0bf31ecdcfd2dd71edc413eefc8dd5f512a3;hpb=07329500b7d9a2e8fcfd9eb97f485deaea9f48f7;p=chaz%2Fhomebank2ledger
diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm
index 748a0bf..f264475 100644
--- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm
+++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm
@@ -3,7 +3,7 @@ package App::HomeBank2Ledger::Formatter::Beancount;
=head1 DESCRIPTION
-This is a formatter for L.
+This is a formatter for L.
=head1 SEE ALSO
@@ -172,7 +172,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;
@@ -220,9 +220,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(', ',
@@ -278,9 +279,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}";