Skip to content

Commit

Permalink
feat(Catch Log Statistics): toggle column "Area Name" (LAN-823)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Mar 22, 2024
1 parent dc501ab commit a24d2df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
1 change: 1 addition & 0 deletions landa/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ Billing History,Kostenübersicht,
LANDA Deliveries and Payments,Kostenübersicht (Lieferungen),
Summarized Billing History,Kostenübersicht Zusammenfassung,
Show Share of other Regional Organizations,Anteil andere RV anzeigen,
Show Area Name,Name der Region anzeigen,
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ frappe.query_reports["Catch Log Statistics"] = {
]
),
},
{
fieldname: "show_area_name",
fieldtype: "Check",
label: "Show Area Name",
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}


def get_columns(show_by_foreign_regional_org: bool = False):
def get_columns(show_by_foreign_regional_org: bool = False, show_area_name: bool = False):
columns = [
{
"fieldname": "water_body",
Expand All @@ -35,25 +35,39 @@ def get_columns(show_by_foreign_regional_org: bool = False):
"label": "Water Body Title",
"width": 200,
},
{
"fieldname": "fish_species",
"fieldtype": "Link",
"label": "Fish Species",
"options": "Fish Species",
"width": 150,
},
{
"fieldname": "amount",
"fieldtype": "Int",
"label": "Number of Fish",
},
{
"fieldname": "weight_in_kg",
"fieldtype": "Float",
"label": "Weight in Kg",
},
]

if show_area_name:
columns.append(
{
"fieldname": "area_name",
"fieldtype": "Data",
"label": "Area Name",
}
)

columns.extend(
[
{
"fieldname": "fish_species",
"fieldtype": "Link",
"label": "Fish Species",
"options": "Fish Species",
"width": 150,
},
{
"fieldname": "amount",
"fieldtype": "Int",
"label": "Number of Fish",
},
{
"fieldname": "weight_in_kg",
"fieldtype": "Float",
"label": "Weight in Kg",
},
]
)

if show_by_foreign_regional_org and is_regional_or_state_employee():
columns.append(
{
Expand All @@ -66,7 +80,7 @@ def get_columns(show_by_foreign_regional_org: bool = False):
return columns


def get_data(filters, show_by_foreign_regional_org: bool = False):
def get_data(filters, show_by_foreign_regional_org: bool = False, show_area_name: bool = False):
entry = frappe.qb.DocType("Catch Log Entry")
child_table = frappe.qb.DocType("Catch Log Fish Table")
qb_filters = get_qb_filters(filters, entry, child_table)
Expand All @@ -78,12 +92,19 @@ def get_data(filters, show_by_foreign_regional_org: bool = False):
.select(
entry.water_body,
entry.water_body_title,
child_table.fish_species,
Sum(child_table.amount),
Sum(child_table.weight_in_kg),
)
)

if show_area_name:
area = frappe.qb.DocType("Fishing Area")
query = query.left_join(area).on(entry.fishing_area == area.name).select(area.area_name)

query = query.select(
child_table.fish_species,
Sum(child_table.amount),
Sum(child_table.weight_in_kg),
)

if show_by_foreign_regional_org and is_regional_or_state_employee():
by_all_regional_orgs = get_subquery(entry, child_table, qb_filters)
by_foreign_regional_orgs = get_subquery(
Expand Down Expand Up @@ -227,8 +248,9 @@ def is_regional_or_state_employee():

def execute(filters=None):
show_by_foreign_regional_org = bool(filters.pop("show_by_foreign_regional_org", None))
show_area_name = bool(filters.pop("show_area_name", None))

return (
get_columns(show_by_foreign_regional_org),
get_data(filters, show_by_foreign_regional_org) or [],
get_columns(show_by_foreign_regional_org, show_area_name),
get_data(filters, show_by_foreign_regional_org, show_area_name) or [],
)

0 comments on commit a24d2df

Please sign in to comment.