Skip to content

Commit

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

refactor: 'group only by voucher' flag in AR/AP report (backport #37869)
  • Loading branch information
ruthra-kumar authored Nov 3, 2023
2 parents 847dd9e + 1e218c1 commit 9dae84f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
8 changes: 7 additions & 1 deletion erpnext/accounts/report/accounts_payable/accounts_payable.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ frappe.query_reports["Accounts Payable"] = {
"fieldname": "show_future_payments",
"label": __("Show Future Payments"),
"fieldtype": "Check",
},
{
"fieldname": "ignore_accounts",
"label": __("Group by Voucher"),
"fieldtype": "Check",
}

],

"formatter": function(value, row, column, data, default_formatter) {
Expand Down Expand Up @@ -175,4 +181,4 @@ function get_party_type_options() {
});
});
return options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ frappe.query_reports["Accounts Receivable"] = {
"fieldname": "show_remarks",
"label": __("Show Remarks"),
"fieldtype": "Check",
},
{
"fieldname": "ignore_accounts",
"label": __("Group by Voucher"),
"fieldtype": "Check",
}

],

"formatter": function(value, row, column, data, default_formatter) {
Expand Down Expand Up @@ -205,4 +211,4 @@ function get_party_type_options() {
});
});
return options;
}
}
22 changes: 18 additions & 4 deletions erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def init_voucher_balance(self):
# build all keys, since we want to exclude vouchers beyond the report date
for ple in self.ple_entries:
# get the balance object for voucher_type
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)

if self.filters.get("ingore_accounts"):
key = (ple.voucher_type, ple.voucher_no, ple.party)
else:
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)

if not key in self.voucher_balance:
self.voucher_balance[key] = frappe._dict(
voucher_type=ple.voucher_type,
Expand Down Expand Up @@ -183,7 +188,10 @@ def get_voucher_balance(self, ple):
):
return

key = (ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party)
if self.filters.get("ingore_accounts"):
key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
else:
key = (ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party)

# If payment is made against credit note
# and credit note is made against a Sales Invoice
Expand All @@ -192,13 +200,19 @@ def get_voucher_balance(self, ple):
if ple.against_voucher_no in self.return_entries:
return_against = self.return_entries.get(ple.against_voucher_no)
if return_against:
key = (ple.account, ple.against_voucher_type, return_against, ple.party)
if self.filters.get("ingore_accounts"):
key = (ple.against_voucher_type, return_against, ple.party)
else:
key = (ple.account, ple.against_voucher_type, return_against, ple.party)

row = self.voucher_balance.get(key)

if not row:
# no invoice, this is an invoice / stand-alone payment / credit note
row = self.voucher_balance.get((ple.account, ple.voucher_type, ple.voucher_no, ple.party))
if self.filters.get("ingore_accounts"):
row = self.voucher_balance.get((ple.voucher_type, ple.voucher_no, ple.party))
else:
row = self.voucher_balance.get((ple.account, ple.voucher_type, ple.voucher_no, ple.party))

row.party_type = ple.party_type
return row
Expand Down

0 comments on commit 9dae84f

Please sign in to comment.