From 5c5ce797b9885ba3d07e25e24ac7828751d71cdd Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Fri, 10 Jan 2025 11:51:25 +0100 Subject: [PATCH] fix: Add back get_profit_and_loss_summary --- .../accounts/report/financial_statements.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 3fc074b588..7e1ec9780b 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -755,3 +755,33 @@ def compute_margin_view_data(data, columns, accumulated_values): margin_percent = round((curr_value / base_value) * 100, 2) data[row_idx][curr_period] = margin_percent + + +@frappe.whitelist() +def get_profit_and_loss_summary(filters=None): + from frappe.desk.query_report import run + # @dokos + + value = 0.0 + if filters: + filters = frappe.parse_json(filters) + + report_filters = { + "company": filters.get("company") or frappe.db.get_default("Company"), + "filter_based_on": "Fiscal Year", + "from_fiscal_year": filters.get("fiscal_year") or frappe.db.get_default("Fiscal Year"), + "to_fiscal_year": filters.get("fiscal_year") or frappe.db.get_default("Fiscal Year"), + "periodicity": "Yearly", + } + + result = run(report_name="Profit and Loss Statement", filters=report_filters) + summary = result.get("report_summary") + + indicator = filters.get("indicator") + index = 0 if indicator == "Income" else (2 if indicator == "Expense" else 4) + value = summary[index].get("value") + + return { + "value": value, + "fieldtype": "Currency", + } -- GitLab