BloomERP

Create a custom lookup

See the built-in reference for the definition fields and available built-ins.

Register an exact reference lookup

Use Django’s default equality compilation with a label specific to your domain.

python
from bloomerp.lookups.definition import LookupDefinition
from bloomerp.lookups.registry import LOOKUP_REGISTRY

reference_match = LookupDefinition(
    id="example_reference_match",
    label="Reference matches",
    description="Compare the field with the supplied reference.",
    expressions=("exact",),
)
LOOKUP_REGISTRY.register(reference_match.id, reference_match)

Let a lookup match draft form values

Use an evaluator with the same case handling as the database expression.

python
from bloomerp.lookups.definition import LookupDefinition
from bloomerp.lookups.registry import LOOKUP_REGISTRY


def matches_prefix(value: object, expected: object) -> bool:
    '''Match a text prefix without regard to case.'''
    return (
        isinstance(value, str)
        and isinstance(expected, str)
        and value.casefold().startswith(expected.casefold())
    )


prefix = LookupDefinition(
    id="example_reference_prefix",
    label="Starts with reference",
    expressions=("istartswith",),
    python_evaluator=matches_prefix,
)
LOOKUP_REGISTRY.register(prefix.id, prefix)