Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added Total Row for Gross Profit Report in Non-Grouped Invoices #45781

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading