CEL Domain Query Builder
Contents
CEL Domain Query Builder#
Module: spp_cel_domain
Overview#
The CEL Domain Query Builder (spp_cel_domain) enables users to write simple, human-readable expressions to filter records in OpenSPP. CEL (Common Expression Language) provides a more intuitive alternative to Odoo's native domain syntax, making it easier for implementers to define eligibility criteria, targeting rules, and data filters.
Purpose#
This module is designed to:
Simplify record filtering: Write expressions like
age_years(r.birthdate) >= 18instead of complex Odoo domainsSupport variable resolution: Reference pre-defined variables (e.g.,
r.household_size) that expand to their underlying expressionsEnable member aggregations: Perform calculations across group members (count, sum, average, min, max)
Provide unified data storage: Manage computed values and external data through the
spp.data.valueandspp.data.providermodels
Module Dependencies#
Dependency |
Description |
|---|---|
|
Odoo core framework |
|
Common OpenSPP utilities and base models |
|
OpenSPP security groups and access control |
|
Registry models for individuals and groups (required for member aggregation) |
Key Features#
CEL Expression Syntax#
CEL expressions support common operators and functions:
Syntax |
Description |
Example |
|---|---|---|
Comparisons |
|
|
Logical |
|
|
Membership |
|
|
Ternary |
|
|
Built-in Functions#
Function |
Description |
Example |
|---|---|---|
|
Calculate age in years from birthdate |
|
|
Current date |
|
|
Date n days in the past |
|
|
Date n months in the past |
|
|
Date n years in the past |
|
|
Check if value is in range |
|
|
Get list length |
|
|
Check if object has key |
|
|
Regex pattern matching |
|
Member Aggregations#
For group/household records, aggregate across members:
Function |
Description |
Example |
|---|---|---|
|
Count matching members |
|
|
Check if any member matches |
|
|
Sum field values |
|
|
Average field values |
|
|
Minimum field value |
|
|
Maximum field value |
|
Profile-Based Compilation#
Expressions are compiled against profiles that define the context:
Profile |
Target Model |
Use Case |
|---|---|---|
|
|
Filter individual registrants |
|
|
Filter group/household registrants |
|
|
Filter program enrollments |
|
|
Filter entitlement records |
Data Providers and Values#
The module includes a unified variable/value storage system:
Data Providers (
spp.data.provider): Define sources of computed or external dataData Values (
spp.data.value): Store computed values for registrants
Integration#
With Programs Module#
When spp_programs is installed, CEL expressions can reference program-related data:
r.program_count > 0 && r.total_entitlements < 10000
With Eligibility Criteria#
Used by program managers to define who qualifies for programs:
age_years(r.birthdate) >= 18 && age_years(r.birthdate) <= 65 && r.monthly_income < 5000
With Targeting Rules#
Filter beneficiaries for specific interventions:
r.area_id.admin_level == 3 && members.count(age_years(m.birthdate) < 5) > 0
CEL Service API#
Other modules can use the CEL service facade:
service = env["spp.cel.service"]
# Compile and execute expression
result = service.compile_expression(
"age_years(r.birthdate) >= 18",
profile="registry_individuals"
)
# result = {"domain": [...], "count": 123, "ids": [...], "valid": True}
# Validate without executing
validation = service.validate_expression(
"r.income < 5000",
profile="registry_individuals"
)
# validation = {"valid": True, "error": None, "explain": "..."}
openspp.org