fix: treat VS as a string on read and write
Go stringified sheet cells with fmt.Sprint, so a numeric VS read with UNFORMATTED_VALUE was rendered as 2.609767878e+09. Text columns of the payments sheet now go through sheets.CellString, which never uses exponent form; bank inference uses the same helper. Both sync implementations now append VS as a text cell so Sheets keeps it a string and leading zeros survive. Existing rows are not rewritten. Python already read VS as a digit string; a regression test pins that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,16 @@ def get_sheets_service(credentials_path: str):
|
||||
return _SHEETS_SERVICE
|
||||
|
||||
|
||||
def as_text_cell(value) -> str:
|
||||
"""Mark a value to be stored as text when written with USER_ENTERED.
|
||||
|
||||
A leading apostrophe stops Sheets from parsing digits as a number (which
|
||||
would drop leading zeros); it is not part of the stored value. Empty stays empty.
|
||||
"""
|
||||
s = "" if value is None else str(value)
|
||||
return f"'{s}" if s else ""
|
||||
|
||||
|
||||
def generate_sync_id(tx: dict) -> str:
|
||||
"""Generate a unique SHA-256 hash for a transaction.
|
||||
|
||||
@@ -209,7 +219,7 @@ def sync_to_sheets(
|
||||
"", # Purpose
|
||||
"", # Inferred Amount
|
||||
tx.get("sender", ""),
|
||||
tx.get("vs", ""),
|
||||
as_text_cell(tx.get("vs", "")),
|
||||
tx.get("message", ""),
|
||||
tx.get("bank_id", ""),
|
||||
sync_id,
|
||||
|
||||
Reference in New Issue
Block a user