Skip to content

Commit

Permalink
feat(Catch Log Statistics): multiselect filters (LAN-823)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Mar 15, 2024
1 parent 15b69e6 commit 9890907
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,38 @@ frappe.query_reports["Catch Log Statistics"] = {
fieldname: "from_year",
fieldtype: "Int",
label: __("From Year"),
mandatory: 0,
wildcard_filter: 0,
default: moment().year() - 1,
},
{
fieldname: "to_year",
fieldtype: "Int",
label: __("To Year"),
mandatory: 0,
wildcard_filter: 0,
default: moment().year(),
},
{
fieldname: "water_body",
fieldtype: "Link",
options: "Water Body",
fieldtype: "MultiSelectList",
label: __("Water Body"),
mandatory: 0,
wildcard_filter: 0,
get_data: (txt) => frappe.db.get_link_options("Water Body", txt),
},
{
fieldname: "fish_species",
fieldtype: "Link",
fieldtype: "MultiSelectList",
label: __("Fish Species"),
options: "Fish Species",
get_data: (txt) => frappe.db.get_link_options("Fish Species", txt),
},
{
fieldname: "organization",
fieldtype: "Link",
options: "Organization",
label: __("Organization"),
mandatory: 0,
wildcard_filter: 0,
default: frappe.defaults.get_user_default("Organization"),
},
{
fieldname: "fishing_area",
fieldtype: "Link",
options: "Fishing Area",
fieldtype: "MultiSelectList",
label: __("Fishing Area"),
mandatory: 0,
wildcard_filter: 0,
get_data: (txt) => frappe.db.get_link_options("Fishing Area", txt),
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,22 @@ def filter_and_group(query, entry: Table, child_table: Table, qb_filters: List[C

def get_qb_filters(filters, entry, child_table):
filters["workflow_state"] = "Approved"
fish_species = filters.pop("fish_species", None)
fish_species = filters.pop("fish_species", [])
water_body = filters.pop("water_body", [])
fishing_area = filters.pop("fishing_area", [])
from_year = filters.pop("from_year", None)
to_year = filters.pop("to_year", None)

qb_filters = [entry[key] == value for key, value in filters.items()]

if fish_species:
qb_filters.append(child_table.fish_species == fish_species)
qb_filters.append(child_table.fish_species.isin(fish_species))

if water_body:
qb_filters.append(entry.water_body.isin(water_body))

if fishing_area:
qb_filters.append(entry.fishing_area.isin(fishing_area))

if from_year:
qb_filters.append(entry.year >= from_year)
Expand Down

0 comments on commit 9890907

Please sign in to comment.