Spaces:
Runtime error
Runtime error
File size: 1,422 Bytes
abd8f87 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | from pathlib import Path
from invoice_reconciler.mapping import FieldMapping, records_from_table, suggest_mapping
from invoice_reconciler.parsers import parse_file
FIXTURES = Path(__file__).parent / "fixtures"
def test_suggest_mapping_prefers_gross_not_first_money_column():
columns = ["Invoice Number", "Adjustment", "Gross Amount", "Net Amount"]
suggestion = suggest_mapping(columns)
assert suggestion.invoice_column == "Invoice Number"
# Must suggest Gross Amount, not Adjustment (first monetary-looking col)
assert suggestion.amount_column == "Gross Amount"
assert "Gross Amount" in suggestion.amount_candidates
def test_never_auto_pick_first_monetary_by_scanning_values():
"""Without amount-like headers, amount_column suggestion stays None."""
columns = ["ColA", "ColB", "ColC"]
suggestion = suggest_mapping(columns)
assert suggestion.amount_column is None
assert suggestion.invoice_column is None
def test_records_use_selected_gross_column():
table = parse_file(FIXTURES / "source.csv")
# If Net were wrongly chosen, INV-100 would be 1233.50
mapping = FieldMapping(invoice_column="Invoice Number", amount_column="Gross Amount")
records = records_from_table(table, mapping)
by_inv = {r.invoice_number: r for r in records if r.invoice_number}
assert by_inv["INV-100"].amount is not None
assert str(by_inv["INV-100"].amount) == "1234.50"
|