Skip to content

Commit

Permalink
feat: accounting dimension filters in gp report
Browse files Browse the repository at this point in the history
(cherry picked from commit d165638)
  • Loading branch information
rtdany10 authored and mergify[bot] committed Jun 24, 2024
1 parent 521cfb3 commit fe9dffb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions erpnext/accounts/report/gross_profit/gross_profit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ frappe.query_reports["Gross Profit"] = {
};
},
},
{
fieldname: "cost_center",
label: __("Cost Center"),
fieldtype: "MultiSelectList",
get_data: function (txt) {
return frappe.db.get_link_options("Cost Center", txt, {
company: frappe.query_report.get_filter_value("company"),
});
},
},
{
fieldname: "project",
label: __("Project"),
fieldtype: "MultiSelectList",
get_data: function (txt) {
return frappe.db.get_link_options("Project", txt, {
company: frappe.query_report.get_filter_value("company"),
});
},
},
],
tree: true,
name_field: "parent",
Expand All @@ -85,3 +105,5 @@ frappe.query_reports["Gross Profit"] = {
return value;
},
};

erpnext.utils.add_dimensions("Gross Profit", 15);
30 changes: 30 additions & 0 deletions erpnext/accounts/report/gross_profit/gross_profit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from frappe.query_builder import Order
from frappe.utils import cint, flt, formatdate

from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions,
get_dimension_with_children,
)
from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
from erpnext.controllers.queries import get_match_cond
from erpnext.stock.report.stock_ledger.stock_ledger import get_item_group_condition
from erpnext.stock.utils import get_incoming_rate
Expand Down Expand Up @@ -787,6 +792,31 @@ def load_invoice_items(self):
if self.filters.get("item_code"):
conditions += " and `tabSales Invoice Item`.item_code = %(item_code)s"

if self.filters.get("cost_center"):
self.filters.cost_center = frappe.parse_json(self.filters.get("cost_center"))
self.filters.cost_center = get_cost_centers_with_children(self.filters.cost_center)
conditions += " and `tabSales Invoice Item`.cost_center in %(cost_center)s"

if self.filters.get("project"):
self.filters.project = frappe.parse_json(self.filters.get("project"))
conditions += " and `tabSales Invoice Item`.project in %(project)s"

accounting_dimensions = get_accounting_dimensions(as_list=False)
if accounting_dimensions:
for dimension in accounting_dimensions:
if self.filters.get(dimension.fieldname):
if frappe.get_cached_value("DocType", dimension.document_type, "is_tree"):
self.filters[dimension.fieldname] = get_dimension_with_children(
dimension.document_type, self.filters.get(dimension.fieldname)
)
conditions += (
f" and `tabSales Invoice Item`.{dimension.fieldname} in %({dimension.fieldname})s"
)
else:
conditions += (
f" and `tabSales Invoice Item`.{dimension.fieldname} in %({dimension.fieldname})s"
)

if self.filters.get("warehouse"):
warehouse_details = frappe.db.get_value(
"Warehouse", self.filters.get("warehouse"), ["lft", "rgt"], as_dict=1
Expand Down

0 comments on commit fe9dffb

Please sign in to comment.