fix(py): coerce amount to float and message to string in tx projection
Two remaining make parity diffs vs Go: - amount: non-numeric sheet values like "---" passed through as strings; Go's parseFloat silently returns 0.0 for unparseable values. Add get_float helper that matches that behaviour. - message: numeric cell values (e.g. a bank reference in the message column) passed through as float64; Go's getVal uses fmt.Sprint and always emits a string. Apply get_str to the message field. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -255,16 +255,25 @@ def fetch_sheet_data(spreadsheet_id: str, credentials_path: str) -> list[dict]:
|
|||||||
return str(int(v))
|
return str(int(v))
|
||||||
return str(v)
|
return str(v)
|
||||||
|
|
||||||
|
def get_float(idx):
|
||||||
|
v = get_val(idx)
|
||||||
|
if isinstance(v, (int, float)):
|
||||||
|
return float(v)
|
||||||
|
try:
|
||||||
|
return float(str(v).strip())
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
tx = {
|
tx = {
|
||||||
"date": format_date(get_val(idx_date)),
|
"date": format_date(get_val(idx_date)),
|
||||||
"amount": get_val(idx_amount),
|
"amount": get_float(idx_amount),
|
||||||
"manual_fix": get_val(idx_manual),
|
"manual_fix": get_val(idx_manual),
|
||||||
"person": get_val(idx_person),
|
"person": get_val(idx_person),
|
||||||
"purpose": get_val(idx_purpose),
|
"purpose": get_val(idx_purpose),
|
||||||
"inferred_amount": get_val(idx_inferred_amount),
|
"inferred_amount": get_val(idx_inferred_amount),
|
||||||
"sender": get_val(idx_sender),
|
"sender": get_val(idx_sender),
|
||||||
"vs": get_str(idx_vs),
|
"vs": get_str(idx_vs),
|
||||||
"message": get_val(idx_message),
|
"message": get_str(idx_message),
|
||||||
"bank_id": get_val(idx_bank_id),
|
"bank_id": get_val(idx_bank_id),
|
||||||
"sync_id": get_val(idx_sync_id),
|
"sync_id": get_val(idx_sync_id),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user