Coverage Helpers¶
nautobot_contract_models.helpers
¶
Cross-cutting helpers — query utilities used by Jobs, views, and templates.
coverage_assignments(target, *, on_date=None, ancestry_attrs=DEFAULT_ANCESTRY_ATTRS)
¶
Return ContractAssignments covering target, including via ancestry.
Looks for assignments whose content_type + object_id matches the
target or any reachable ancestor (tenant, location, rack, parent
device). Filtered to active coverage on on_date (default today),
where "active" means:
- The Contract's start_date <= on_date <= end_date
- The Assignment's coverage_start (if set) <= on_date
- The Assignment's coverage_end (if set) >= on_date
Sorted with primary assignments first, then by contract end_date descending (most-recent renewal first).
The expected pattern: a Device detail page renders this as "Coverage (including via Tenant / Location)" so on-call engineers can see the full set of contracts that apply, not just the explicit assignments.
Source code in src/nautobot_contract_models/helpers.py
has_active_coverage(target, *, on_date=None, ancestry_attrs=DEFAULT_ANCESTRY_ATTRS)
¶
Cheap boolean: does target have any active contract coverage today?
Used by the CoverageGapJob and the "Uncovered Devices" home dashboard
panel. Accepts the same ancestry_attrs knob as
:func:coverage_assignments so callers can narrow the walk (e.g. to
check direct-only coverage on a Device).