forked from EvergreenCrypto/docker-finance
container: lib_taxes: add support for bitcoin.tax TransferAccount column
- Is backward compatible to all rules without TransferAccount added. * TransferAccount value must be added via custom rules. - Upstream appears to support TransferAccount for all years even though it was introduced specifically for tax years 2025+ (mileage may vary).
This commit is contained in:
@@ -455,16 +455,17 @@ function lib_taxes::__taxes_print()
|
||||
| xan select '"posting-comment"' \
|
||||
| tail -n +2 \
|
||||
| sed -e 's:"::g' -e '/^$/d' \
|
||||
| gawk -v tag="$_tag" -v is_trades="$_is_trades" \
|
||||
| gawk \
|
||||
-v tag="$_tag" \
|
||||
-v is_income="$_is_income" -v is_spends="$_is_spends" -v is_trades="$_is_trades" \
|
||||
'BEGIN {
|
||||
FS=OFS=","
|
||||
|
||||
str_one="Date" OFS "Action" OFS "Account" OFS "Symbol" OFS "Volume" OFS "Currency" OFS "Total"
|
||||
str_two="FeeCurrency" OFS "Fee"
|
||||
str_three="TransferAccount"
|
||||
|
||||
has_fee = (is_trades ? 1 : 0)
|
||||
printf (has_fee ? str_one OFS str_two : str_one OFS "Memo")
|
||||
|
||||
printf (is_trades ? str_one OFS str_two : str_one OFS "Memo" OFS str_three)
|
||||
printf "\n"
|
||||
}
|
||||
{
|
||||
@@ -477,12 +478,14 @@ function lib_taxes::__taxes_print()
|
||||
Volume = $5
|
||||
Currency = $6
|
||||
Total = $7
|
||||
Memo = (has_fee ? "" : $8)
|
||||
if (has_fee)
|
||||
Memo = (is_trades ? "" : $8)
|
||||
if (is_trades)
|
||||
{
|
||||
FeeCurrency = (has_fee && $9 != "" ? $8 : "")
|
||||
FeeCurrency = ($9 != "" ? $8 : "")
|
||||
Fee = (FeeCurrency && $9 != 0 ? $9 : "")
|
||||
}
|
||||
# NOTE: TransferAccount value added by custom-rules
|
||||
TransferAccount = (is_trades ? "" : $9)
|
||||
|
||||
# Total is a literal 0. Get market value from bitcoin.tax
|
||||
if (Total == 0) {Total=""}
|
||||
@@ -565,7 +568,7 @@ function lib_taxes::__taxes_print()
|
||||
|
||||
# TODO: HACK: print SPEND line for non-fiat fee (see #51)
|
||||
# NOTE: cost-basis *MUST* be calculated above or within preprocess
|
||||
if (is_trades && has_fee && FeeCurrency != "USD" && Fee)
|
||||
if (is_trades && FeeCurrency != "USD" && Fee)
|
||||
{
|
||||
printf Date OFS "SPEND" OFS Account OFS
|
||||
printf FeeCurrency OFS Fee OFS "USD"
|
||||
@@ -590,7 +593,7 @@ function lib_taxes::__taxes_print()
|
||||
printf Currency OFS
|
||||
printf Total OFS
|
||||
|
||||
if (has_fee)
|
||||
if (!is_income)
|
||||
{
|
||||
# TODO: HACK: see #51 (and related lib_taxes work-around)
|
||||
# NOTE: cost-basis *MUST* be calculated within preprocess
|
||||
@@ -600,12 +603,19 @@ function lib_taxes::__taxes_print()
|
||||
}
|
||||
else
|
||||
{
|
||||
printf FeeCurrency OFS Fee
|
||||
if (is_trades)
|
||||
{
|
||||
printf FeeCurrency OFS Fee
|
||||
}
|
||||
else
|
||||
{
|
||||
printf Memo OFS TransferAccount
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf Memo
|
||||
printf Memo OFS TransferAccount
|
||||
}
|
||||
|
||||
printf "\n"
|
||||
@@ -1261,6 +1271,13 @@ function lib_taxes::__reports_patch()
|
||||
&& sort -ru -o "$_spends" "$_spends"
|
||||
fi
|
||||
|
||||
# Allow impl to add to header while providing backward compat for all rules (repo/custom)
|
||||
local -r _files=("$_income" "$_spends" "$_trades")
|
||||
local -r _csvclean=("csvclean" "--fill-short-rows")
|
||||
for _file in "${_files[@]}"; do
|
||||
[[ -f "$_file" && -s "$_file" ]] && echo "$("${_csvclean[@]}" "${_file}")" >"${_file}"
|
||||
done
|
||||
|
||||
#
|
||||
# Verify success of patches
|
||||
#
|
||||
@@ -1303,7 +1320,7 @@ function lib_taxes::__reports_obfs()
|
||||
# NOTE: functions inherit local vars
|
||||
case "$_arg_tag" in
|
||||
income | spends)
|
||||
local _all_columns="Date,Action,Account,Symbol,Volume,Currency,Total,Memo"
|
||||
local _all_columns="Date,Action,Account,Symbol,Volume,Currency,Total,Memo,TransferAccount"
|
||||
local _obfs_columns=("Account" "Memo")
|
||||
;;
|
||||
trades)
|
||||
|
||||
Reference in New Issue
Block a user