27 lines
922 B
Python
27 lines
922 B
Python
import csv
|
|
from datetime import datetime
|
|
from typing import List
|
|
from ..ir import TaxLot
|
|
|
|
|
|
def read_taxlots_from_csv(path: str) -> List[TaxLot]:
|
|
"""Read a simple CSV with headers: id,acquisition_date,basis,quantity,market_value
|
|
|
|
Returns list of TaxLot. This adapter is intentionally minimal for Phase-0.
|
|
"""
|
|
lots = []
|
|
with open(path, newline="") as f:
|
|
rdr = csv.DictReader(f)
|
|
for row in rdr:
|
|
acq = row.get("acquisition_date")
|
|
acq_date = datetime.strptime(acq, "%Y-%m-%d").date() if acq else None
|
|
lot = TaxLot(
|
|
id=row.get("id"),
|
|
acquisition_date=acq_date,
|
|
basis=float(row.get("basis", 0)),
|
|
quantity=float(row.get("quantity", 0)),
|
|
market_value=float(row.get("market_value")) if row.get("market_value") else None,
|
|
)
|
|
lots.append(lot)
|
|
return lots
|