app.utils.amount_parser module¶
Amount parser — handles every real-world amount format found in bank CSVs.
- Supported formats:
Standard: 1234.56 | 1,234.56 European: 1.234,56 | 1234,56 Indian: 1,23,456.78 Accounting: (1234.56) | (1,234.56) ← negative Suffix sign: 1234.56 DR | 1234.56 CR Symbol prefix: $1,234.56 | £500.00 | €1.234,56 | ₹1,23,456 Missing/null: - | N/A | nil | (empty)
- class app.utils.amount_parser.ParsedAmount(value: decimal.Decimal, direction: str, is_inferred: bool, original: str, warning: str | None)[source]¶
Bases:
object- direction: str¶
- is_inferred: bool¶
- original: str¶
- value: Decimal¶
- warning: str | None¶
- app.utils.amount_parser.parse_amount(raw: str, default_direction: str = 'D') ParsedAmount | None[source]¶
Parse a raw amount string into a normalized ParsedAmount.
- Parameters:
raw – The raw string from the CSV cell.
default_direction – Fall-back direction when no sign info (‘C’ or ‘D’).
- Returns:
ParsedAmount, or None if the value represents a missing/null amount.
- Raises:
ValueError – If the string is non-null but unparseable.
- app.utils.amount_parser.parse_split_amounts(debit_raw: str | None, credit_raw: str | None) ParsedAmount | None[source]¶
Parse bank CSVs that have separate Debit and Credit columns. Returns a single ParsedAmount with the appropriate direction.
- Many bank formats have two separate columns rather than a signed amount:
- Date | Description | Debit | Credit | Balance |