fix(ledger): keep legacy amount wire type and preserve dividend tax decimals

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-09 13:00:23 +00:00
committed by GitHub
co-authored by genichin
parent fde5b33f05
commit d3601d32dc
8 changed files with 131 additions and 19 deletions
+17 -9
View File
@@ -688,11 +688,14 @@ def record_ledger_trade_v1(
def _manual_entry_to_response(entry) -> ManualLedgerResponse:
action = (entry.action or entry.side or "").upper()
amount = (
(entry.price_decimal if entry.price_decimal is not None else Decimal(str(entry.price)))
if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"}
else None
)
amount: float | Decimal | None = None
if action == "DIVIDEND":
amount = entry.price_decimal if entry.price_decimal is not None else Decimal(str(entry.price))
elif action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT"}:
amount = float(entry.price)
tax_value: float | Decimal = float(entry.tax_amount)
if action == "DIVIDEND":
tax_value = entry.tax_amount_decimal if entry.tax_amount_decimal is not None else Decimal(str(entry.tax_amount))
return ManualLedgerResponse(
ledger_entry_id=entry.ledger_entry_id,
portfolio_id=entry.portfolio_id,
@@ -701,7 +704,7 @@ def _manual_entry_to_response(entry) -> ManualLedgerResponse:
quantity=entry.quantity,
price=entry.price,
fee=entry.fee_amount,
tax=entry.tax_amount,
tax=tax_value,
executed_at=entry.executed_at,
note=entry.note,
recorded_at=entry.recorded_at,
@@ -791,9 +794,14 @@ def _decode_ledger_cursor(cursor: str, *, portfolio_id: str, source: str | None)
def _ledger_entry_to_history_item(entry) -> LedgerHistoryItem:
action = (entry.action or entry.side or "").upper()
amount = None
if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"}:
amount: float | Decimal | None = None
if action == "DIVIDEND":
amount = entry.price_decimal if entry.price_decimal is not None else Decimal(str(entry.price))
elif action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT"}:
amount = float(entry.price)
tax_amount: float | Decimal | None = entry.tax_amount
if action == "DIVIDEND":
tax_amount = entry.tax_amount_decimal if entry.tax_amount_decimal is not None else Decimal(str(entry.tax_amount))
return LedgerHistoryItem(
ledger_entry_id=entry.ledger_entry_id,
portfolio_id=entry.portfolio_id,
@@ -807,7 +815,7 @@ def _ledger_entry_to_history_item(entry) -> LedgerHistoryItem:
amount=amount,
price=entry.price,
fee_amount=entry.fee_amount,
tax_amount=entry.tax_amount,
tax_amount=tax_amount,
note=entry.note,
cash_balance_after=entry.cash_balance_after,
asset_quantity_after=entry.asset_quantity_after,