mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-16 07:58:38 +00:00
fix: use company currency instead of global default in report (backport #56561)
Reports like Sales Order Trends and Purchase Order Trends showed the global default currency symbol instead of the transacting company's currency. Threads the company currency through conditions["company_currency"] in trends.get_columns and uses it for both the chart's currency and the Total row. The chart now skips the grand-total row by its label instead of by a falsy first periodic cell, so the already-summed Total row is not added into the datapoints a second time. Backport of #56561 (frappe/erpnext). Two parts of the original PR are not included: the Landed Cost Report does not exist on this branch, and the trends report test files do not exist either.
This commit is contained in:
@@ -73,6 +73,7 @@ def execute(filters=None):
|
|||||||
"parent_section": None,
|
"parent_section": None,
|
||||||
"indent": 0.0,
|
"indent": 0.0,
|
||||||
"section": cash_flow_section["section_header"],
|
"section": cash_flow_section["section_header"],
|
||||||
|
"currency": company_currency,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ def get_data_when_grouped_by_invoice(columns, gross_profit_data, filters, group_
|
|||||||
)
|
)
|
||||||
if total_base_amount
|
if total_base_amount
|
||||||
else 0,
|
else 0,
|
||||||
|
"currency": filters.currency,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -269,6 +270,7 @@ def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_
|
|||||||
"buying_amount": total_buying_amount,
|
"buying_amount": total_buying_amount,
|
||||||
"gross_profit": total_gross_profit,
|
"gross_profit": total_gross_profit,
|
||||||
"gross_profit_percent": flt(gross_profit_percent, currency_precision),
|
"gross_profit_percent": flt(gross_profit_percent, currency_precision),
|
||||||
|
"currency": filters.currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
total_row = [total_row.get(col, None) for col in [*group_columns, "currency"]]
|
total_row = [total_row.get(col, None) for col in [*group_columns, "currency"]]
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ def execute(filters=None):
|
|||||||
conditions = get_columns(filters, "Purchase Order")
|
conditions = get_columns(filters, "Purchase Order")
|
||||||
data = get_data(filters, conditions)
|
data = get_data(filters, conditions)
|
||||||
chart_data = get_chart_data(data, conditions, filters)
|
chart_data = get_chart_data(data, conditions, filters)
|
||||||
|
|
||||||
return conditions["columns"], data, None, chart_data
|
return conditions["columns"], data, None, chart_data
|
||||||
|
|
||||||
|
|
||||||
@@ -39,9 +38,15 @@ def get_chart_data(data, conditions, filters):
|
|||||||
labels = [column.split(":")[0] for column in columns]
|
labels = [column.split(":")[0] for column in columns]
|
||||||
datapoints = [0] * len(labels)
|
datapoints = [0] * len(labels)
|
||||||
|
|
||||||
|
group_by_col_idx = None
|
||||||
|
if filters.get("group_by"):
|
||||||
|
group_by_col_idx = conditions["columns"].index(conditions["grbc"][0])
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
# If group by filter, don't add first row of group (it's already summed)
|
# Skip the final grand-total row
|
||||||
if not row[start]:
|
if row[0] == f"'{_('Total')}'":
|
||||||
|
continue
|
||||||
|
if group_by_col_idx is not None and row[group_by_col_idx] == "":
|
||||||
continue
|
continue
|
||||||
# Remove None values and compute only periodic data
|
# Remove None values and compute only periodic data
|
||||||
row = [x if x else 0 for x in row[start:-2]]
|
row = [x if x else 0 for x in row[start:-2]]
|
||||||
@@ -60,4 +65,6 @@ def get_chart_data(data, conditions, filters):
|
|||||||
"type": "line",
|
"type": "line",
|
||||||
"lineOptions": {"regionFill": 1},
|
"lineOptions": {"regionFill": 1},
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"currency": conditions.get("company_currency"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import DateTimeLikeObject, getdate, today
|
from frappe.utils import DateTimeLikeObject, getdate, today
|
||||||
|
|
||||||
|
import erpnext
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +43,9 @@ def get_columns(filters, trans):
|
|||||||
"addl_tables": based_on_details["addl_tables"],
|
"addl_tables": based_on_details["addl_tables"],
|
||||||
"addl_tables_relational_cond": based_on_details.get("addl_tables_relational_cond", ""),
|
"addl_tables_relational_cond": based_on_details.get("addl_tables_relational_cond", ""),
|
||||||
}
|
}
|
||||||
|
conditions["company_currency"] = (
|
||||||
|
erpnext.get_company_currency(filters.get("company")) if filters.get("company") else None
|
||||||
|
)
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
@@ -206,7 +210,7 @@ def get_data(filters, conditions):
|
|||||||
|
|
||||||
data.append(des)
|
data.append(des)
|
||||||
|
|
||||||
total_row = calculate_total_row(data1, conditions["columns"])
|
total_row = calculate_total_row(data1, conditions["columns"], conditions.get("company_currency"))
|
||||||
data.append(total_row)
|
data.append(total_row)
|
||||||
else:
|
else:
|
||||||
data = frappe.db.sql(
|
data = frappe.db.sql(
|
||||||
@@ -231,20 +235,23 @@ def get_data(filters, conditions):
|
|||||||
as_list=1,
|
as_list=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
total_row = calculate_total_row(data, conditions["columns"])
|
total_row = calculate_total_row(data, conditions["columns"], conditions.get("company_currency"))
|
||||||
data.append(total_row)
|
data.append(total_row)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def calculate_total_row(data, columns):
|
def calculate_total_row(data, columns, company_currency=None):
|
||||||
def wrap_in_quotes(label):
|
def wrap_in_quotes(label):
|
||||||
return f"'{label}'"
|
return f"'{label}'"
|
||||||
|
|
||||||
total_values = {}
|
total_values = {}
|
||||||
|
currency_col_idx = None
|
||||||
for i, col in enumerate(columns):
|
for i, col in enumerate(columns):
|
||||||
if "Float" in col or "Currency/currency" in col:
|
if "Float" in col or "Currency/currency" in col:
|
||||||
total_values[i] = 0
|
total_values[i] = 0
|
||||||
|
if "Link/Currency" in col:
|
||||||
|
currency_col_idx = i
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
for i in total_values.keys():
|
for i in total_values.keys():
|
||||||
@@ -254,6 +261,9 @@ def calculate_total_row(data, columns):
|
|||||||
for i in range(1, len(columns)):
|
for i in range(1, len(columns)):
|
||||||
total_row.append(total_values.get(i, None))
|
total_row.append(total_values.get(i, None))
|
||||||
|
|
||||||
|
if currency_col_idx is not None:
|
||||||
|
total_row[currency_col_idx] = company_currency
|
||||||
|
|
||||||
return total_row
|
return total_row
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
from erpnext.controllers.trends import get_columns, get_data
|
from erpnext.controllers.trends import get_columns, get_data
|
||||||
@@ -40,9 +39,15 @@ def get_chart_data(data, conditions, filters):
|
|||||||
labels = [column.split(":")[0] for column in columns]
|
labels = [column.split(":")[0] for column in columns]
|
||||||
datapoints = [0] * len(labels)
|
datapoints = [0] * len(labels)
|
||||||
|
|
||||||
|
group_by_col_idx = None
|
||||||
|
if filters.get("group_by"):
|
||||||
|
group_by_col_idx = conditions["columns"].index(conditions["grbc"][0])
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
# If group by filter, don't add first row of group (it's already summed)
|
# Skip the final grand-total row
|
||||||
if not row[start]:
|
if row[0] == f"'{_('Total')}'":
|
||||||
|
continue
|
||||||
|
if group_by_col_idx is not None and row[group_by_col_idx] == "":
|
||||||
continue
|
continue
|
||||||
# Remove None values and compute only periodic data
|
# Remove None values and compute only periodic data
|
||||||
row = [x if x else 0 for x in row[start:-2]]
|
row = [x if x else 0 for x in row[start:-2]]
|
||||||
@@ -59,4 +64,6 @@ def get_chart_data(data, conditions, filters):
|
|||||||
"type": "line",
|
"type": "line",
|
||||||
"lineOptions": {"regionFill": 1},
|
"lineOptions": {"regionFill": 1},
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"currency": conditions.get("company_currency"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,15 @@ def get_chart_data(data, conditions, filters):
|
|||||||
labels = [column.split(":")[0] for column in columns]
|
labels = [column.split(":")[0] for column in columns]
|
||||||
datapoints = [0] * len(labels)
|
datapoints = [0] * len(labels)
|
||||||
|
|
||||||
|
group_by_col_idx = None
|
||||||
|
if filters.get("group_by"):
|
||||||
|
group_by_col_idx = conditions["columns"].index(conditions["grbc"][0])
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
# If group by filter, don't add first row of group (it's already summed)
|
# Skip the final grand-total row
|
||||||
if not row[start]:
|
if row[0] == f"'{_('Total')}'":
|
||||||
|
continue
|
||||||
|
if group_by_col_idx is not None and row[group_by_col_idx] == "":
|
||||||
continue
|
continue
|
||||||
# Remove None values and compute only periodic data
|
# Remove None values and compute only periodic data
|
||||||
row = [x if x else 0 for x in row[start:-2]]
|
row = [x if x else 0 for x in row[start:-2]]
|
||||||
@@ -58,4 +64,6 @@ def get_chart_data(data, conditions, filters):
|
|||||||
"type": "line",
|
"type": "line",
|
||||||
"lineOptions": {"regionFill": 1},
|
"lineOptions": {"regionFill": 1},
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"currency": conditions.get("company_currency"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ def execute(filters=None):
|
|||||||
conditions = get_columns(filters, "Delivery Note")
|
conditions = get_columns(filters, "Delivery Note")
|
||||||
data = get_data(filters, conditions)
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
chart_data = get_chart_data(data, filters)
|
chart_data = get_chart_data(data, conditions, filters)
|
||||||
|
|
||||||
return conditions["columns"], data, None, chart_data
|
return conditions["columns"], data, None, chart_data
|
||||||
|
|
||||||
|
|
||||||
def get_chart_data(data, filters):
|
def get_chart_data(data, conditions, filters):
|
||||||
def wrap_in_quotes(label):
|
def wrap_in_quotes(label):
|
||||||
return f"'{label}'"
|
return f"'{label}'"
|
||||||
|
|
||||||
@@ -52,4 +52,6 @@ def get_chart_data(data, filters):
|
|||||||
},
|
},
|
||||||
"type": "bar",
|
"type": "bar",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"currency": conditions.get("company_currency"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ def execute(filters=None):
|
|||||||
conditions = get_columns(filters, "Purchase Receipt")
|
conditions = get_columns(filters, "Purchase Receipt")
|
||||||
data = get_data(filters, conditions)
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
chart_data = get_chart_data(data, filters)
|
chart_data = get_chart_data(data, conditions, filters)
|
||||||
|
|
||||||
return conditions["columns"], data, None, chart_data
|
return conditions["columns"], data, None, chart_data
|
||||||
|
|
||||||
|
|
||||||
def get_chart_data(data, filters):
|
def get_chart_data(data, conditions, filters):
|
||||||
def wrap_in_quotes(label):
|
def wrap_in_quotes(label):
|
||||||
return f"'{label}'"
|
return f"'{label}'"
|
||||||
|
|
||||||
@@ -53,4 +53,6 @@ def get_chart_data(data, filters):
|
|||||||
"type": "bar",
|
"type": "bar",
|
||||||
"colors": ["#5e64ff"],
|
"colors": ["#5e64ff"],
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"currency": conditions.get("company_currency"),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user