refactor: additional filters and columns in Payment Ledger report (#34577)
1. 'Party type' and 'Party' filters have been added 2. checkbox to include Amount in Acccount Currency 3. Grouping vouchers on Party 4. Replaced Company with Posting Date
This commit is contained in:
parent
8c7fa5712b
commit
f7780cdb58
@ -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",
|
"fieldname":"voucher_no",
|
||||||
"label": __("Voucher No"),
|
"label": __("Voucher No"),
|
||||||
@ -49,6 +72,20 @@ function get_filters() {
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"width": 100,
|
"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;
|
return filters;
|
||||||
|
@ -17,34 +17,26 @@ class PaymentLedger(object):
|
|||||||
self.ple = qb.DocType("Payment Ledger Entry")
|
self.ple = qb.DocType("Payment Ledger Entry")
|
||||||
|
|
||||||
def init_voucher_dict(self):
|
def init_voucher_dict(self):
|
||||||
|
|
||||||
if self.voucher_amount:
|
if self.voucher_amount:
|
||||||
s = set()
|
# for each ple, using group_by_key to create a key and assign it to +/- list
|
||||||
# build a set of unique vouchers
|
|
||||||
for ple in self.voucher_amount:
|
for ple in self.voucher_amount:
|
||||||
key = (ple.voucher_type, ple.voucher_no, ple.party)
|
group_by_key = None
|
||||||
s.add(key)
|
if not self.filters.group_party:
|
||||||
|
group_by_key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
||||||
# for each unique vouchers, initialize +/- list
|
|
||||||
for key in s:
|
|
||||||
self.voucher_dict[key] = frappe._dict(increase=list(), decrease=list())
|
|
||||||
|
|
||||||
# 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:
|
else:
|
||||||
target = self.voucher_dict.get(against_key).decrease
|
group_by_key = (ple.party_type, ple.party)
|
||||||
|
|
||||||
|
target = None
|
||||||
|
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)
|
# this if condition will lose unassigned ple entries(against_voucher doc doesn't have ple)
|
||||||
# need to somehow include the stray entries as well.
|
# need to somehow include the stray entries as well.
|
||||||
if target is not None:
|
if target is not None:
|
||||||
entry = frappe._dict(
|
entry = frappe._dict(
|
||||||
company=ple.company,
|
posting_date=ple.posting_date,
|
||||||
account=ple.account,
|
account=ple.account,
|
||||||
party_type=ple.party_type,
|
party_type=ple.party_type,
|
||||||
party=ple.party,
|
party=ple.party,
|
||||||
@ -66,10 +58,10 @@ class PaymentLedger(object):
|
|||||||
|
|
||||||
for value in self.voucher_dict.values():
|
for value in self.voucher_dict.values():
|
||||||
voucher_data = []
|
voucher_data = []
|
||||||
if value.increase != []:
|
if value.get("increase"):
|
||||||
voucher_data.extend(value.increase)
|
voucher_data.extend(value.get("increase"))
|
||||||
if value.decrease != []:
|
if value.get("decrease"):
|
||||||
voucher_data.extend(value.decrease)
|
voucher_data.extend(value.get("decrease"))
|
||||||
|
|
||||||
if voucher_data:
|
if voucher_data:
|
||||||
# balance row
|
# balance row
|
||||||
@ -117,6 +109,12 @@ class PaymentLedger(object):
|
|||||||
if self.filters.against_voucher_no:
|
if self.filters.against_voucher_no:
|
||||||
self.conditions.append(self.ple.against_voucher_no == 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):
|
def get_data(self):
|
||||||
ple = self.ple
|
ple = self.ple
|
||||||
|
|
||||||
@ -134,7 +132,13 @@ class PaymentLedger(object):
|
|||||||
def get_columns(self):
|
def get_columns(self):
|
||||||
options = None
|
options = None
|
||||||
self.columns.append(
|
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(
|
self.columns.append(
|
||||||
@ -160,7 +164,11 @@ class PaymentLedger(object):
|
|||||||
)
|
)
|
||||||
self.columns.append(
|
self.columns.append(
|
||||||
dict(
|
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(
|
self.columns.append(
|
||||||
@ -176,8 +184,8 @@ class PaymentLedger(object):
|
|||||||
dict(
|
dict(
|
||||||
label=_("Against Voucher No"),
|
label=_("Against Voucher No"),
|
||||||
fieldname="against_voucher_no",
|
fieldname="against_voucher_no",
|
||||||
fieldtype="data",
|
fieldtype="Dynamic Link",
|
||||||
options=options,
|
options="against_voucher_type",
|
||||||
width="100",
|
width="100",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -209,7 +217,7 @@ class PaymentLedger(object):
|
|||||||
self.get_columns()
|
self.get_columns()
|
||||||
self.get_data()
|
self.get_data()
|
||||||
|
|
||||||
# initialize dictionary and group using against voucher
|
# initialize dictionary and group using key
|
||||||
self.init_voucher_dict()
|
self.init_voucher_dict()
|
||||||
|
|
||||||
# convert dictionary to list and add balance rows
|
# convert dictionary to list and add balance rows
|
||||||
|
Loading…
Reference in New Issue
Block a user