From 314a6671de7dc5458a20baac7d9a487d6494d4e8 Mon Sep 17 00:00:00 2001 From: stumpylog <797416+stumpylog@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:45:58 -0700 Subject: [PATCH] Fixes exact custom field monetary exact searching --- src/documents/filters.py | 5 ++-- .../tests/test_api_filter_by_custom_fields.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/documents/filters.py b/src/documents/filters.py index b2b226ee1..9ee829fc9 100644 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -514,9 +514,8 @@ class CustomFieldQueryParser: value_field_name = CustomFieldInstance.get_value_field_name( custom_field.data_type, ) - if ( - custom_field.data_type == CustomField.FieldDataType.MONETARY - and op in self.EXPR_BY_CATEGORY["arithmetic"] + if custom_field.data_type == CustomField.FieldDataType.MONETARY and ( + op in self.EXPR_BY_CATEGORY["arithmetic"] or op in {"exact", "in"} ): value_field_name = "value_monetary_amount" has_field = Q(custom_fields__field=custom_field) diff --git a/src/documents/tests/test_api_filter_by_custom_fields.py b/src/documents/tests/test_api_filter_by_custom_fields.py index b28fec777..bbb38f3bb 100644 --- a/src/documents/tests/test_api_filter_by_custom_fields.py +++ b/src/documents/tests/test_api_filter_by_custom_fields.py @@ -453,6 +453,32 @@ class TestCustomFieldsSearch(DirectoriesMixin, APITestCase): ), ) + def test_exact_monetary(self) -> None: + # "exact" should match by numeric amount, ignoring currency code prefix. + self._assert_query_match_predicate( + ["monetary_field", "exact", "100"], + lambda document: ( + "monetary_field" in document + and document["monetary_field"] == "USD100.00" + ), + ) + self._assert_query_match_predicate( + ["monetary_field", "exact", "101"], + lambda document: ( + "monetary_field" in document and document["monetary_field"] == "101.00" + ), + ) + + def test_in_monetary(self) -> None: + # "in" should match by numeric amount, ignoring currency code prefix. + self._assert_query_match_predicate( + ["monetary_field", "in", ["100", "50"]], + lambda document: ( + "monetary_field" in document + and document["monetary_field"] in {"USD100.00", "EUR50.00"} + ), + ) + # ==========================================================# # Subset check (document link field only) # # ==========================================================#