From 2884738864b7d236d39d2126d2d03ae5bed9b829 Mon Sep 17 00:00:00 2001 From: Gokulnath <95605271+Gokulnath17@users.noreply.github.com> Date: Wed, 1 Feb 2023 18:44:15 +0530 Subject: [PATCH] feat: adding warehouse filter for gross profit report (#33397) Co-authored-by: ruthra kumar --- .../accounts/report/gross_profit/gross_profit.js | 14 ++++++++++++++ .../accounts/report/gross_profit/gross_profit.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.js b/erpnext/accounts/report/gross_profit/gross_profit.js index 615804ef62..e89d42977b 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.js +++ b/erpnext/accounts/report/gross_profit/gross_profit.js @@ -50,6 +50,20 @@ frappe.query_reports["Gross Profit"] = { "fieldtype": "Link", "options": "Sales Person" }, + { + "fieldname": "warehouse", + "label": __("Warehouse"), + "fieldtype": "Link", + "options": "Warehouse", + "get_query": function () { + var company = frappe.query_report.get_filter_value('company'); + return { + filters: [ + ["Warehouse", "company", "=", company] + ] + }; + }, + }, ], "tree": true, "name_field": "parent", diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 25e7891a49..e23265b5e7 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -775,6 +775,13 @@ class GrossProfitGenerator(object): if self.filters.get("item_code"): conditions += " and `tabSales Invoice Item`.item_code = %(item_code)s" + if self.filters.get("warehouse"): + warehouse_details = frappe.db.get_value( + "Warehouse", self.filters.get("warehouse"), ["lft", "rgt"], as_dict=1 + ) + if warehouse_details: + conditions += f" and `tabSales Invoice Item`.warehouse in (select name from `tabWarehouse` wh where wh.lft >= {warehouse_details.lft} and wh.rgt <= {warehouse_details.rgt} and warehouse = wh.name)" + self.si_list = frappe.db.sql( """ select