container: hledger-flow: paypal: support latest fiat header

- Breaking changes due to additional columns (not backwards-compatible).
- Adds 'fees' subaccount and new tags from the additional columns.
This commit is contained in:
2025-07-02 15:25:07 -07:00
parent db8f5154b5
commit 6fc4a1527d
2 changed files with 51 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -42,12 +42,13 @@ source "${DOCKER_FINANCE_CONTAINER_REPO}/src/hledger-flow/lib/lib_preprocess.bas
function parse_report()
{
lib_preprocess::assert_header "\"Date\",\"Time\",\"TimeZone\",\"Name\",\"Type\",\"Status\",\"Currency\",\"Amount\",\"Receipt ID\",\"Balance\""
# Supports "Balance Affecting" reports
lib_preprocess::assert_header "\"Date\",\"Time\",\"TimeZone\",\"Name\",\"Type\",\"Status\",\"Currency\",\"Amount\",\"Fees\",\"Total\",\"Exchange Rate\",\"Receipt ID\",\"Balance\",\"Transaction ID\",\"Item Title\""
# Paypal is known to allow commas within description ("Name") and amounts
# NOTE: using custom timezone offset instead of provided timezone
# TODO: refactor xsv/sed -> gawk (the sed line should remove non-csv commas and quotations)
xsv select "Date,Time,Name,Type,Status,Currency,Amount,Receipt ID,Balance" "$global_in_path" \
xsv select "Date,Time,Name,Type,Status,Currency,Amount,Fees,Total,Exchange Rate,Receipt ID,Balance,Transaction ID,Item Title" "$global_in_path" \
| sed -e 's:, : :g' -e 's:,",:,:g' -e 's:,"\([0-9]*\),:,\1:g' -e 's:,"-\([0-9]*\),:,-\1:g' -e 's:"::g' \
| gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \
'{
@@ -67,10 +68,6 @@ function parse_report()
# Scrap existing alphanum timezone for a timezone offset
cmd = "date \"+%F %T %z\" --date="date_time | getline timestamp
# Need an integer if amount or balance are empty
amount=($7 != "" ? $7 : "0")
balance=($9 != "" ? $9 : "0")
# Print
printf timestamp OFS # timestamp
printf $3 OFS # description (Name)
@@ -78,12 +75,23 @@ function parse_report()
printf $5 OFS # status
printf $6 OFS # currency
direction=(amount ~ /^-/ ? "OUT" : "IN")
sub(/^-/, "", amount)
printf amount OFS # amount
direction=($7 ~ /^-/ ? "OUT" : "IN")
sub(/^-/, "", $7)
printf $7 OFS # amount
printf $8 OFS # code (Receipt ID)
printf balance OFS # balance
sub(/^-/, "", $8)
printf $8 OFS # fees
sub(/^-/, "", $9)
printf $9 OFS # total
printf $10 OFS # exchange rate
printf $11 OFS # code (Receipt ID)
printf $12 OFS # balance
printf $13 OFS # txid (Transaction ID)
printf $14 OFS # title (Item Title)
printf direction OFS
printf global_subaccount OFS
@@ -126,8 +134,13 @@ function parse_crypto()
printf OFS # status
printf OFS # currency
printf OFS # amount
printf OFS # fees
printf OFS # total
printf OFS # exchange rate
printf OFS # code (Receipt ID)
printf OFS # balance
printf OFS # txid (Transaction ID)
printf OFS # title (Item Title)
printf OFS # direction
printf global_subaccount OFS

View File

@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
fields timestamp,description_,type,status_,currency_,amount_,code_,balance_,direction,subaccount,in_value,in_ticker,out_value,out_ticker,tx_fee_value,tx_fee_ticker,fiat_value
fields timestamp,description_,type,status_,currency_,amount_,fees,total,exchange_rate,code_,balance_,txid,title,direction,subaccount,in_value,in_ticker,out_value,out_ticker,tx_fee_value,tx_fee_ticker,fiat_value
date-format %Y-%m-%d %H:%M:%S %z
date %timestamp
@@ -30,8 +30,24 @@ comment type:%type, status:%status_, direction:%direction
if %description_ ([0-9]|[a-z])
comment description:%description_, type:%type, status:%status_, direction:%direction
if %code_ ([0-9]|[a-z])
comment description:%description_, type:%type, status:%status_, code:%code_, direction:%direction
if %description_ ([0-9]|[a-z])
& %title ([0-9]|[a-z])
comment description:%description_, title:%title, type:%type, status:%status_, direction:%direction
if %description_ ([0-9]|[a-z])
& %txid ([0-9]|[a-z])
comment description:%description_, type:%type, txid:%txid, status:%status_, direction:%direction
if %description_ ([0-9]|[a-z])
& %txid ([0-9]|[a-z])
& %title ([0-9]|[a-z])
comment description:%description_, title:%title, type:%type, txid:%txid, status:%status_, direction:%direction
if %description_ ([0-9]|[a-z])
& %txid ([0-9]|[a-z])
& %title ([0-9]|[a-z])
& %code ([0-9]|[a-z])
comment description:%description_, title:%title, type:%type, txid:%txid, status:%status_, code:%code_, direction:%direction
# ---------------------------------------------------------------------------- #
# IN #
@@ -54,6 +70,13 @@ if %direction ^OUT$
if %direction ^OUT$
account2 expenses:paypal:%subaccount:%currency_
if %direction ^OUT$
& %fees [1-9]
account3 assets:paypal:%subaccount:%currency_
amount3 -%fees %currency_
account4 expenses:paypal:%subaccount:fees:%currency_
amount4 %fees %currency_
if %direction ^OUT$
& %description_ ^PayPal$
& %type ^Account Hold for Open Authorization$