Skip to content

Commit

Permalink
Merge pull request frappe#34583 from frappe/mergify/bp/version-14-hot…
Browse files Browse the repository at this point in the history
…fix/pr-34577

refactor: additional filters and columns in Payment Ledger report (backport frappe#34577)
  • Loading branch information
ruthra-kumar authored Mar 24, 2023
2 parents 070dea1 + 57ecac4 commit 37f2ba8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 28 deletions.
37 changes: 37 additions & 0 deletions erpnext/accounts/report/payment_ledger/payment_ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ function get_filters() {
});
}
},
{
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
"default": "",
on_change: function() {
frappe.query_report.set_filter_value('party', "");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "MultiSelectList",
get_data: function(txt) {
if (!frappe.query_report.filters) return;

let party_type = frappe.query_report.get_filter_value('party_type');
if (!party_type) return;

return frappe.db.get_link_options(party_type, txt);
},
},
{
"fieldname":"voucher_no",
"label": __("Voucher No"),
Expand All @@ -49,6 +72,20 @@ function get_filters() {
"fieldtype": "Data",
"width": 100,
},
{
"fieldname":"include_account_currency",
"label": __("Include Account Currency"),
"fieldtype": "Check",
"width": 100,
},
{
"fieldname":"group_party",
"label": __("Group by Party"),
"fieldtype": "Check",
"width": 100,
},



]
return filters;
Expand Down
64 changes: 36 additions & 28 deletions erpnext/accounts/report/payment_ledger/payment_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,26 @@ def __init__(self, filters=None):
self.ple = qb.DocType("Payment Ledger Entry")

def init_voucher_dict(self):

if self.voucher_amount:
s = set()
# build a set of unique vouchers
# for each ple, using group_by_key to create a key and assign it to +/- list
for ple in self.voucher_amount:
key = (ple.voucher_type, ple.voucher_no, ple.party)
s.add(key)

# for each unique vouchers, initialize +/- list
for key in s:
self.voucher_dict[key] = frappe._dict(increase=list(), decrease=list())
group_by_key = None
if not self.filters.group_party:
group_by_key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
else:
group_by_key = (ple.party_type, ple.party)

# for each ple, using against voucher and amount, assign it to +/- list
# group by against voucher
for ple in self.voucher_amount:
against_key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
target = None
if self.voucher_dict.get(against_key):
if ple.amount > 0:
target = self.voucher_dict.get(against_key).increase
else:
target = self.voucher_dict.get(against_key).decrease
if ple.amount > 0:
target = self.voucher_dict.setdefault(group_by_key, {}).setdefault("increase", [])
else:
target = self.voucher_dict.setdefault(group_by_key, {}).setdefault("decrease", [])

# this if condition will lose unassigned ple entries(against_voucher doc doesn't have ple)
# need to somehow include the stray entries as well.
if target is not None:
entry = frappe._dict(
company=ple.company,
posting_date=ple.posting_date,
account=ple.account,
party_type=ple.party_type,
party=ple.party,
Expand All @@ -66,10 +58,10 @@ def build_data(self):

for value in self.voucher_dict.values():
voucher_data = []
if value.increase != []:
voucher_data.extend(value.increase)
if value.decrease != []:
voucher_data.extend(value.decrease)
if value.get("increase"):
voucher_data.extend(value.get("increase"))
if value.get("decrease"):
voucher_data.extend(value.get("decrease"))

if voucher_data:
# balance row
Expand Down Expand Up @@ -117,6 +109,12 @@ def build_conditions(self):
if self.filters.against_voucher_no:
self.conditions.append(self.ple.against_voucher_no == self.filters.against_voucher_no)

if self.filters.party_type:
self.conditions.append(self.ple.party_type == self.filters.party_type)

if self.filters.party:
self.conditions.append(self.ple.party.isin(self.filters.party))

def get_data(self):
ple = self.ple

Expand All @@ -134,7 +132,13 @@ def get_data(self):
def get_columns(self):
options = None
self.columns.append(
dict(label=_("Company"), fieldname="company", fieldtype="data", options=options, width="100")
dict(
label=_("Posting Date"),
fieldname="posting_date",
fieldtype="Date",
options=options,
width="100",
)
)

self.columns.append(
Expand All @@ -160,7 +164,11 @@ def get_columns(self):
)
self.columns.append(
dict(
label=_("Voucher No"), fieldname="voucher_no", fieldtype="data", options=options, width="100"
label=_("Voucher No"),
fieldname="voucher_no",
fieldtype="Dynamic Link",
options="voucher_type",
width="100",
)
)
self.columns.append(
Expand All @@ -176,8 +184,8 @@ def get_columns(self):
dict(
label=_("Against Voucher No"),
fieldname="against_voucher_no",
fieldtype="data",
options=options,
fieldtype="Dynamic Link",
options="against_voucher_type",
width="100",
)
)
Expand Down Expand Up @@ -209,7 +217,7 @@ def run(self):
self.get_columns()
self.get_data()

# initialize dictionary and group using against voucher
# initialize dictionary and group using key
self.init_voucher_dict()

# convert dictionary to list and add balance rows
Expand Down

0 comments on commit 37f2ba8

Please sign in to comment.