fix: квантование суммы «лучшей догадки» до 0,01 (T20.1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
This commit is contained in:
parent
2da7bff71a
commit
aa46e7ad4a
@ -73,7 +73,7 @@ def _guess(digits: str, text: str, sign_form: SignForm, *, negative: bool) -> Am
|
|||||||
"""«Лучшая догадка»: цифры подряд, не длиннее 16, иначе значение не число."""
|
"""«Лучшая догадка»: цифры подряд, не длиннее 16, иначе значение не число."""
|
||||||
if not digits or len(digits) > MAX_INTEGER_DIGITS:
|
if not digits or len(digits) > MAX_INTEGER_DIGITS:
|
||||||
return AmountParse(None, text, False, sign_form)
|
return AmountParse(None, text, False, sign_form)
|
||||||
amount = Decimal(digits)
|
amount = _quantize(Decimal(digits))
|
||||||
return AmountParse(-amount if negative else amount, None, False, sign_form)
|
return AmountParse(-amount if negative else amount, None, False, sign_form)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -241,7 +241,7 @@
|
|||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"column_index": 2,
|
"column_index": 2,
|
||||||
"amount": "428311",
|
"amount": "428311.00",
|
||||||
"string_value": null,
|
"string_value": null,
|
||||||
"text": "42831 1",
|
"text": "42831 1",
|
||||||
"confidence": 90.0,
|
"confidence": 90.0,
|
||||||
|
|||||||
@ -117,3 +117,12 @@ def test_sign_inside_parentheses_is_invalid(rules: Rules) -> None:
|
|||||||
def test_leading_comma_is_edge_trash(rules: Rules) -> None:
|
def test_leading_comma_is_edge_trash(rules: Rules) -> None:
|
||||||
parsed = parse_amount(",5", OCR, rules)
|
parsed = parse_amount(",5", OCR, rules)
|
||||||
assert (parsed.amount, parsed.is_recognized) == (D("5"), False)
|
assert (parsed.amount, parsed.is_recognized) == (D("5"), False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_guess_amount_is_quantized_to_cents(rules: Rules) -> None:
|
||||||
|
"""T20.1: «лучшая догадка» квантуется как прочие пути; в контракте — две цифры после точки."""
|
||||||
|
parsed = parse_amount("42831 1", Source.OCR, rules)
|
||||||
|
assert parsed.amount == D("428311.00") and parsed.amount.as_tuple().exponent == -2 # noqa: PLR2004 — знаков после запятой
|
||||||
|
assert format(parsed.amount, "f") == "428311.00"
|
||||||
|
negative = parse_amount("(42831 1)", Source.OCR, rules)
|
||||||
|
assert negative.amount is not None and format(negative.amount, "f") == "-428311.00"
|
||||||
|
|||||||
Reference in New Issue
Block a user