Skip to content

Commit

Permalink
Merge pull request frappe#44345 from ruthra-kumar/fix_broken_export_i…
Browse files Browse the repository at this point in the history
…n_p_l_statements

fix: broken export on financial statements
  • Loading branch information
ruthra-kumar authored Nov 26, 2024
2 parents 4983dac + ea6e022 commit f8655cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 0 additions & 1 deletion erpnext/accounts/report/cash_flow/cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def get_report_summary(summary_data, currency):

def get_chart_data(columns, data, currency):
labels = [d.get("label") for d in columns[2:]]
print(data)
datasets = [
{
"name": section.get("section").replace("'", ""),
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/financial_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def get_cost_centers_with_children(cost_centers):
def get_columns(periodicity, period_list, accumulated_values=1, company=None, cash_flow=False):
columns = [
{
"fieldname": "stub",
"fieldname": "account",
"label": _("Account") if not cash_flow else _("Section"),
"fieldtype": "Link",
"options": "Account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# MIT License. See license.txt

import frappe
from frappe.desk.query_report import export_query
from frappe.tests import IntegrationTestCase
from frappe.utils import getdate, today

Expand Down Expand Up @@ -90,3 +91,21 @@ def test_profit_and_loss_output_and_summary(self):
with self.subTest(current_period_key=current_period_key):
self.assertEqual(acc[current_period_key], 150)
self.assertEqual(acc["total"], 150)

def test_p_and_l_export(self):
self.create_sales_invoice(qty=1, rate=150)

filters = self.get_report_filters()
frappe.local.form_dict = frappe._dict(
{
"report_name": "Profit and Loss Statement",
"file_format_type": "CSV",
"filters": filters,
"visible_idx": [0, 1, 2, 3, 4, 5, 6],
}
)
export_query()
contents = frappe.response["filecontent"].decode()
sales_account = frappe.db.get_value("Company", self.company, "default_income_account")

self.assertIn(sales_account, contents)
4 changes: 2 additions & 2 deletions erpnext/public/js/financial_statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ erpnext.financial_statements = {

return value;
} else if (frappe.query_report.get_filter_value("selected_view") == "Margin" && data) {
if (column.fieldname == "stub" && data.account_name == __("Income")) {
if (column.fieldname == "account" && data.account_name == __("Income")) {
//Taking the total income from each column (for all the financial years) as the base (100%)
this.baseData = row;
}
Expand All @@ -52,7 +52,7 @@ erpnext.financial_statements = {
}
}

if (data && column.fieldname == "stub") {
if (data && column.fieldname == "account") {
// first column
value = data.section_name || data.account_name || value;

Expand Down

0 comments on commit f8655cb

Please sign in to comment.