Skip to content

Commit

Permalink
Merge pull request #45844 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-45781

fix: Added Total Row for `Gross Profit` Report in Non-Grouped Invoices (backport #45781)
  • Loading branch information
ruthra-kumar authored Feb 11, 2025
2 parents 09114e6 + e432ae9 commit ebce6be
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions erpnext/accounts/report/gross_profit/gross_profit.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,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):
total_base_amount = 0
total_buying_amount = 0

group_columns = group_wise_columns.get(scrub(filters.group_by))

for src in gross_profit_data.grouped_data:
row = []
for col in group_wise_columns.get(scrub(filters.group_by)):
row.append(src.get(col))
total_base_amount += src.base_amount or 0.00
total_buying_amount += src.buying_amount or 0.00

row.append(filters.currency)
row = [src.get(col) for col in group_columns] + [filters.currency]

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):
columns = []
Expand Down

0 comments on commit ebce6be

Please sign in to comment.