Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters: Match metadata keys for postings as well #1945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/fava/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,15 @@ def p_simple_expr_key(self, p: list[Any]) -> None:
def _key(entry: Directive) -> bool:
if hasattr(entry, key):
return match(getattr(entry, key) or "")
if entry.meta is not None and key in entry.meta:
return match(entry.meta.get(key))
return False
return (
entry.meta is not None
and key in entry.meta
and match(entry.meta.get(key))
) or any(
match(posting.meta.get(key))
for posting in getattr(entry, "postings", [])
if posting.meta is not None and key in posting.meta
)

p[0] = _key

Expand Down
7 changes: 4 additions & 3 deletions src/fava/help/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ This final filter allows you to filter entries by various attributes.
for an exact match instead.
- Search in payee and narration if no specific entry attribute is given, e.g.
`"Cash withdrawal"`. For Note directives, the comment will be searched.
- Filter for entries having certain metadata values: `document:"\.pdf$"`. Note
that if the entry has an attribute of the same name as the metadata key, the
filter will apply to the entry attribute, not the metadata value.
- Filter for entries or postings having certain metadata values:
`document:"\.pdf$"`. Note that if the entry has an attribute of the same name
as the metadata key, the filter will apply to the entry attribute, not the
metadata value.
- Exclude entries that match a filter by prepending a `-` to it, e.g. `-#tag` or
`-(^link #tag)`.
- To match entries by posting attributes, you can use `any()` and `all()`, e.g.,
Expand Down
Loading