Export sats and whole kroner, and add the price column
This commit is contained in:
1 parent
4b28cd100a
commit
6b79452e95
1 file changed
+25
-19
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
Semicolon separated with a UTF-8 BOM and Norwegian number formatting, so the
|
Semicolon separated with a UTF-8 BOM and Norwegian number formatting, so the
|
||||||
file opens directly in a Norwegian spreadsheet. `report_csv()` starts the file
|
file opens directly in a Norwegian spreadsheet. `report_csv()` starts the file
|
||||||
and carries the BOM; `transactions_csv()` is appended after it.
|
and carries the BOM; `transactions_csv()` is appended after it. Kroner are
|
||||||
|
written as whole kroner and BTC quantities as whole sats, as in the UI.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import database
|
import database
|
||||||
@@ -29,8 +30,9 @@ TRANSACTION_HEADINGS = (
|
|||||||
"Type",
|
"Type",
|
||||||
"Konto",
|
"Konto",
|
||||||
"Til konto",
|
"Til konto",
|
||||||
"Antall inn (BTC)",
|
"Pris (kr)",
|
||||||
"Antall ut (BTC)",
|
"Antall inn (sats)",
|
||||||
|
"Antall ut (sats)",
|
||||||
"Beløp inn (kr)",
|
"Beløp inn (kr)",
|
||||||
"Beløp ut (kr)",
|
"Beløp ut (kr)",
|
||||||
"Verdi (kr)",
|
"Verdi (kr)",
|
||||||
@@ -52,13 +54,13 @@ def _cell(value):
|
|||||||
|
|
||||||
|
|
||||||
def _amount(ore):
|
def _amount(ore):
|
||||||
"""An amount in kroner, with Norwegian formatting."""
|
"""Whole kroner, empty when there is no amount."""
|
||||||
return "" if ore is None else rates.ore_to_nok(ore)
|
return "" if ore is None else rates.kroner_whole(ore)
|
||||||
|
|
||||||
|
|
||||||
def _btc(sats):
|
def _sats(sats):
|
||||||
"""A BTC quantity, empty when there is none."""
|
"""A whole number of sats, empty when there is none."""
|
||||||
return "" if not sats else rates.sats_to_btc(sats)
|
return "" if not sats else rates.group_int(sats)
|
||||||
|
|
||||||
|
|
||||||
def _percent(value):
|
def _percent(value):
|
||||||
@@ -89,6 +91,9 @@ def report_csv(year):
|
|||||||
lines.append("Inntekt (kr)" + SEPARATOR + _amount(totals["inntekt_ore"]))
|
lines.append("Inntekt (kr)" + SEPARATOR + _amount(totals["inntekt_ore"]))
|
||||||
lines.append("Skatt (kr)" + SEPARATOR + _amount(totals["skatt_ore"]))
|
lines.append("Skatt (kr)" + SEPARATOR + _amount(totals["skatt_ore"]))
|
||||||
lines.append("Formuesskatt (kr)" + SEPARATOR + _amount(totals["formuesskatt_ore"]))
|
lines.append("Formuesskatt (kr)" + SEPARATOR + _amount(totals["formuesskatt_ore"]))
|
||||||
|
lines.append(
|
||||||
|
"Forvaltningskostnad (sats)" + SEPARATOR + _sats(totals["admin_cost_sats"])
|
||||||
|
)
|
||||||
lines.append(
|
lines.append(
|
||||||
"Forvaltningskostnad (kr)" + SEPARATOR + _amount(totals["admin_cost_ore"])
|
"Forvaltningskostnad (kr)" + SEPARATOR + _amount(totals["admin_cost_ore"])
|
||||||
)
|
)
|
||||||
@@ -97,7 +102,7 @@ def report_csv(year):
|
|||||||
lines.append(SEPARATOR.join((
|
lines.append(SEPARATOR.join((
|
||||||
"Konto",
|
"Konto",
|
||||||
"Behaldning %",
|
"Behaldning %",
|
||||||
"Antall (BTC)",
|
"Antall (sats)",
|
||||||
"Formue (kr)",
|
"Formue (kr)",
|
||||||
"Gevinst (kr)",
|
"Gevinst (kr)",
|
||||||
"Tap (kr)",
|
"Tap (kr)",
|
||||||
@@ -108,7 +113,7 @@ def report_csv(year):
|
|||||||
lines.append(SEPARATOR.join((
|
lines.append(SEPARATOR.join((
|
||||||
_cell(account["name"]),
|
_cell(account["name"]),
|
||||||
_percent(account["share_percent"]),
|
_percent(account["share_percent"]),
|
||||||
_btc(account["sats"]),
|
_sats(account["sats"]),
|
||||||
_amount(account["formue_ore"]),
|
_amount(account["formue_ore"]),
|
||||||
_amount(account["gevinst_ore"]),
|
_amount(account["gevinst_ore"]),
|
||||||
_amount(account["tap_ore"]),
|
_amount(account["tap_ore"]),
|
||||||
@@ -119,21 +124,21 @@ def report_csv(year):
|
|||||||
|
|
||||||
if data["non_taxable"]:
|
if data["non_taxable"]:
|
||||||
lines.append(SEPARATOR.join((
|
lines.append(SEPARATOR.join((
|
||||||
"Ikkje skattepliktig", "Antall (BTC)", "Gevinst (kr)", "Tap (kr)"
|
"Ikkje skattepliktig", "Antall (sats)", "Gevinst (kr)", "Tap (kr)"
|
||||||
)))
|
)))
|
||||||
for row in data["non_taxable"]:
|
for row in data["non_taxable"]:
|
||||||
lines.append(SEPARATOR.join((
|
lines.append(SEPARATOR.join((
|
||||||
_cell(row["name"]),
|
_cell(row["name"]),
|
||||||
_btc(row["sats"]),
|
_sats(row["sats"]),
|
||||||
_amount(row["gevinst_ore"]),
|
_amount(row["gevinst_ore"]),
|
||||||
_amount(row["tap_ore"]),
|
_amount(row["tap_ore"]),
|
||||||
)))
|
)))
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
if data["custody_totals"]:
|
if data["custody_totals"]:
|
||||||
lines.append("TOT (fysisk behaldning)" + SEPARATOR + "Antall (BTC)")
|
lines.append("TOT (fysisk behaldning)" + SEPARATOR + "Antall (sats)")
|
||||||
for row in data["custody_totals"]:
|
for row in data["custody_totals"]:
|
||||||
lines.append(_cell(row["name"]) + SEPARATOR + _btc(row["sats"]))
|
lines.append(_cell(row["name"]) + SEPARATOR + _sats(row["sats"]))
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
lines.append(_cell(data["skattemelding"]["note"]))
|
lines.append(_cell(data["skattemelding"]["note"]))
|
||||||
@@ -141,7 +146,7 @@ def report_csv(year):
|
|||||||
|
|
||||||
|
|
||||||
def transactions_csv(year):
|
def transactions_csv(year):
|
||||||
"""The year's transactions with the cost basis each one consumed."""
|
"""The year's transactions with the consumed cost and the bitcoin price."""
|
||||||
year = int(year)
|
year = int(year)
|
||||||
conn = database.connect()
|
conn = database.connect()
|
||||||
try:
|
try:
|
||||||
@@ -151,7 +156,7 @@ def transactions_csv(year):
|
|||||||
" m.name AS market_name, d.name AS to_market_name,"
|
" m.name AS market_name, d.name AS to_market_name,"
|
||||||
" COALESCE(SUM(c.cost_ore), 0) AS cost_ore"
|
" COALESCE(SUM(c.cost_ore), 0) AS cost_ore"
|
||||||
" FROM transactions t"
|
" FROM transactions t"
|
||||||
" JOIN markets m ON m.id = t.market_id"
|
" LEFT JOIN markets m ON m.id = t.market_id"
|
||||||
" LEFT JOIN markets d ON d.id = t.to_market_id"
|
" LEFT JOIN markets d ON d.id = t.to_market_id"
|
||||||
" LEFT JOIN lot_consumptions c ON c.tx_id = t.id"
|
" LEFT JOIN lot_consumptions c ON c.tx_id = t.id"
|
||||||
" WHERE t.date >= ? AND t.date <= ?"
|
" WHERE t.date >= ? AND t.date <= ?"
|
||||||
@@ -169,12 +174,13 @@ def transactions_csv(year):
|
|||||||
_cell(TYPE_LABELS.get(row["type"], row["type"])),
|
_cell(TYPE_LABELS.get(row["type"], row["type"])),
|
||||||
_cell(row["market_name"]),
|
_cell(row["market_name"]),
|
||||||
_cell(row["to_market_name"]),
|
_cell(row["to_market_name"]),
|
||||||
_btc(row["leg_in_sats"]),
|
_amount(tax.btc_price_ore(row)),
|
||||||
_btc(row["leg_out_sats"]),
|
_sats(row["leg_in_sats"]),
|
||||||
|
_sats(row["leg_out_sats"]),
|
||||||
_amount(row["leg_in_ore"]),
|
_amount(row["leg_in_ore"]),
|
||||||
_amount(row["leg_out_ore"]),
|
_amount(row["leg_out_ore"]),
|
||||||
_amount(row["value_ore"]),
|
_amount(row["value_ore"]),
|
||||||
_btc(row["fee_sats"]),
|
_sats(row["fee_sats"]),
|
||||||
_amount(row["fee_ore"]),
|
_amount(row["fee_ore"]),
|
||||||
_amount(row["cost_ore"]),
|
_amount(row["cost_ore"]),
|
||||||
"Ja" if row["taxable"] else "Nei",
|
"Ja" if row["taxable"] else "Nei",
|
||||||
|
|||||||
Reference in new issue
Block a user