Merge pull request #45843 from frappe/mergify/bp/version-14-hotfix/pr-45781
fix: Added Total Row for `Gross Profit` Report in Non-Grouped Invoices (backport #45781)
This commit is contained in:
@@ -207,15 +207,34 @@ def get_data_when_grouped_by_invoice(columns, gross_profit_data, filters, group_
|
|||||||
|
|
||||||
|
|
||||||
def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_columns, data):
|
def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_columns, data):
|
||||||
for src in gross_profit_data.grouped_data:
|
total_base_amount = 0
|
||||||
row = []
|
total_buying_amount = 0
|
||||||
for col in group_wise_columns.get(scrub(filters.group_by)):
|
|
||||||
row.append(src.get(col))
|
|
||||||
|
|
||||||
row.append(filters.currency)
|
group_columns = group_wise_columns.get(scrub(filters.group_by))
|
||||||
|
|
||||||
|
for src in gross_profit_data.grouped_data:
|
||||||
|
total_base_amount += src.base_amount or 0.00
|
||||||
|
total_buying_amount += src.buying_amount or 0.00
|
||||||
|
|
||||||
|
row = [src.get(col) for col in group_columns] + [filters.currency]
|
||||||
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
|
total_gross_profit = total_base_amount - total_buying_amount
|
||||||
|
currency_precision = cint(frappe.db.get_default("currency_precision")) or 3
|
||||||
|
gross_profit_percent = (total_gross_profit / total_base_amount * 100.0) if total_base_amount else 0
|
||||||
|
|
||||||
|
total_row = {
|
||||||
|
group_columns[0]: "Total",
|
||||||
|
"base_amount": total_base_amount,
|
||||||
|
"buying_amount": total_buying_amount,
|
||||||
|
"gross_profit": total_gross_profit,
|
||||||
|
"gross_profit_percent": flt(gross_profit_percent, currency_precision),
|
||||||
|
}
|
||||||
|
|
||||||
|
total_row = [total_row.get(col, None) for col in [*group_columns, "currency"]]
|
||||||
|
data.append(total_row)
|
||||||
|
|
||||||
|
|
||||||
def get_columns(group_wise_columns, filters):
|
def get_columns(group_wise_columns, filters):
|
||||||
columns = []
|
columns = []
|
||||||
|
|||||||
Reference in New Issue
Block a user