fix: fetch ple for all party types
This commit is contained in:
@@ -7,7 +7,7 @@ from erpnext.accounts.report.accounts_receivable.accounts_receivable import Rece
|
|||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
args = {
|
args = {
|
||||||
"party_type": "Supplier",
|
"account_type": "Payable",
|
||||||
"naming_by": ["Buying Settings", "supp_master_name"],
|
"naming_by": ["Buying Settings", "supp_master_name"],
|
||||||
}
|
}
|
||||||
return ReceivablePayableReport(filters).run(args)
|
return ReceivablePayableReport(filters).run(args)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from erpnext.accounts.utils import get_currency_precision
|
|||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
args = {
|
args = {
|
||||||
"party_type": "Customer",
|
"account_type": "Receivable",
|
||||||
"naming_by": ["Selling Settings", "cust_master_name"],
|
"naming_by": ["Selling Settings", "cust_master_name"],
|
||||||
}
|
}
|
||||||
return ReceivablePayableReport(filters).run(args)
|
return ReceivablePayableReport(filters).run(args)
|
||||||
@@ -70,8 +70,11 @@ class ReceivablePayableReport(object):
|
|||||||
"Company", self.filters.get("company"), "default_currency"
|
"Company", self.filters.get("company"), "default_currency"
|
||||||
)
|
)
|
||||||
self.currency_precision = get_currency_precision() or 2
|
self.currency_precision = get_currency_precision() or 2
|
||||||
self.dr_or_cr = "debit" if self.filters.party_type == "Customer" else "credit"
|
self.dr_or_cr = "debit" if self.filters.account_type == "Receivable" else "credit"
|
||||||
self.party_type = self.filters.party_type
|
self.account_type = self.filters.account_type
|
||||||
|
self.party_type = frappe.db.get_all(
|
||||||
|
"Party Type", {"account_type": self.account_type}, pluck="name"
|
||||||
|
)
|
||||||
self.party_details = {}
|
self.party_details = {}
|
||||||
self.invoices = set()
|
self.invoices = set()
|
||||||
self.skip_total_row = 0
|
self.skip_total_row = 0
|
||||||
@@ -197,6 +200,7 @@ class ReceivablePayableReport(object):
|
|||||||
# no invoice, this is an invoice / stand-alone payment / credit note
|
# no invoice, this is an invoice / stand-alone payment / credit note
|
||||||
row = self.voucher_balance.get((ple.voucher_type, ple.voucher_no, ple.party))
|
row = self.voucher_balance.get((ple.voucher_type, ple.voucher_no, ple.party))
|
||||||
|
|
||||||
|
row.party_type = ple.party_type
|
||||||
return row
|
return row
|
||||||
|
|
||||||
def update_voucher_balance(self, ple):
|
def update_voucher_balance(self, ple):
|
||||||
@@ -207,8 +211,9 @@ class ReceivablePayableReport(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# amount in "Party Currency", if its supplied. If not, amount in company currency
|
# amount in "Party Currency", if its supplied. If not, amount in company currency
|
||||||
if self.filters.get(scrub(self.party_type)):
|
for party_type in self.party_type:
|
||||||
amount = ple.amount_in_account_currency
|
if self.filters.get(scrub(party_type)):
|
||||||
|
amount = ple.amount_in_account_currency
|
||||||
else:
|
else:
|
||||||
amount = ple.amount
|
amount = ple.amount
|
||||||
amount_in_account_currency = ple.amount_in_account_currency
|
amount_in_account_currency = ple.amount_in_account_currency
|
||||||
@@ -362,7 +367,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
def get_invoice_details(self):
|
def get_invoice_details(self):
|
||||||
self.invoice_details = frappe._dict()
|
self.invoice_details = frappe._dict()
|
||||||
if self.party_type == "Customer":
|
if self.account_type == "Receivable":
|
||||||
si_list = frappe.db.sql(
|
si_list = frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
select name, due_date, po_no
|
select name, due_date, po_no
|
||||||
@@ -390,7 +395,7 @@ class ReceivablePayableReport(object):
|
|||||||
d.sales_person
|
d.sales_person
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.party_type == "Supplier":
|
if self.account_type == "Payable":
|
||||||
for pi in frappe.db.sql(
|
for pi in frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
select name, due_date, bill_no, bill_date
|
select name, due_date, bill_no, bill_date
|
||||||
@@ -421,12 +426,10 @@ class ReceivablePayableReport(object):
|
|||||||
# customer / supplier name
|
# customer / supplier name
|
||||||
party_details = self.get_party_details(row.party) or {}
|
party_details = self.get_party_details(row.party) or {}
|
||||||
row.update(party_details)
|
row.update(party_details)
|
||||||
if row.voucher_type == "Expense Claim":
|
for party_type in self.party_type:
|
||||||
row.party_type = "Employee"
|
if self.filters.get(scrub(party_type)):
|
||||||
else:
|
row.currency = row.account_currency
|
||||||
row.party_type = self.party_type
|
break
|
||||||
if self.filters.get(scrub(self.filters.party_type)):
|
|
||||||
row.currency = row.account_currency
|
|
||||||
else:
|
else:
|
||||||
row.currency = self.company_currency
|
row.currency = self.company_currency
|
||||||
|
|
||||||
@@ -552,7 +555,7 @@ class ReceivablePayableReport(object):
|
|||||||
where
|
where
|
||||||
payment_entry.docstatus < 2
|
payment_entry.docstatus < 2
|
||||||
and payment_entry.posting_date > %s
|
and payment_entry.posting_date > %s
|
||||||
and payment_entry.party_type = %s
|
and payment_entry.party_type in %s
|
||||||
""",
|
""",
|
||||||
(self.filters.report_date, self.party_type),
|
(self.filters.report_date, self.party_type),
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
@@ -562,11 +565,11 @@ class ReceivablePayableReport(object):
|
|||||||
if self.filters.get("party"):
|
if self.filters.get("party"):
|
||||||
amount_field = (
|
amount_field = (
|
||||||
"jea.debit_in_account_currency - jea.credit_in_account_currency"
|
"jea.debit_in_account_currency - jea.credit_in_account_currency"
|
||||||
if self.party_type == "Supplier"
|
if self.account_type == "Payable"
|
||||||
else "jea.credit_in_account_currency - jea.debit_in_account_currency"
|
else "jea.credit_in_account_currency - jea.debit_in_account_currency"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
amount_field = "jea.debit - " if self.party_type == "Supplier" else "jea.credit"
|
amount_field = "jea.debit - " if self.account_type == "Payable" else "jea.credit"
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
@@ -584,7 +587,7 @@ class ReceivablePayableReport(object):
|
|||||||
where
|
where
|
||||||
je.docstatus < 2
|
je.docstatus < 2
|
||||||
and je.posting_date > %s
|
and je.posting_date > %s
|
||||||
and jea.party_type = %s
|
and jea.party_type in %s
|
||||||
and jea.reference_name is not null and jea.reference_name != ''
|
and jea.reference_name is not null and jea.reference_name != ''
|
||||||
group by je.name, jea.reference_name
|
group by je.name, jea.reference_name
|
||||||
having future_amount > 0
|
having future_amount > 0
|
||||||
@@ -623,13 +626,17 @@ class ReceivablePayableReport(object):
|
|||||||
row.future_ref = ", ".join(row.future_ref)
|
row.future_ref = ", ".join(row.future_ref)
|
||||||
|
|
||||||
def get_return_entries(self):
|
def get_return_entries(self):
|
||||||
doctype = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
doctype = "Sales Invoice" if self.account_type == "Receivable" else "Purchase Invoice"
|
||||||
filters = {"is_return": 1, "docstatus": 1, "company": self.filters.company}
|
filters = {"is_return": 1, "docstatus": 1, "company": self.filters.company}
|
||||||
party_field = scrub(self.filters.party_type)
|
or_filters = {}
|
||||||
if self.filters.get(party_field):
|
for party_type in self.party_type:
|
||||||
filters.update({party_field: self.filters.get(party_field)})
|
party_field = scrub(party_type)
|
||||||
|
if self.filters.get(party_field):
|
||||||
|
or_filters.update({party_field: self.filters.get(party_field)})
|
||||||
self.return_entries = frappe._dict(
|
self.return_entries = frappe._dict(
|
||||||
frappe.get_all(doctype, filters, ["name", "return_against"], as_list=1)
|
frappe.get_all(
|
||||||
|
doctype, filters=filters, or_filters=or_filters, fields=["name", "return_against"], as_list=1
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_ageing(self, row):
|
def set_ageing(self, row):
|
||||||
@@ -720,6 +727,7 @@ class ReceivablePayableReport(object):
|
|||||||
)
|
)
|
||||||
.where(ple.delinked == 0)
|
.where(ple.delinked == 0)
|
||||||
.where(Criterion.all(self.qb_selection_filter))
|
.where(Criterion.all(self.qb_selection_filter))
|
||||||
|
.where(Criterion.any(self.or_filters))
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.filters.get("group_by_party"):
|
if self.filters.get("group_by_party"):
|
||||||
@@ -750,19 +758,18 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
def prepare_conditions(self):
|
def prepare_conditions(self):
|
||||||
self.qb_selection_filter = []
|
self.qb_selection_filter = []
|
||||||
party_type_field = scrub(self.party_type)
|
self.or_filters = []
|
||||||
if self.party_type == "Supplier":
|
for party_type in self.party_type:
|
||||||
self.qb_selection_filter.append(self.ple.party_type.isin([self.party_type, "Employee"]))
|
party_type_field = scrub(party_type)
|
||||||
else:
|
self.or_filters.append(self.ple.party_type == party_type)
|
||||||
self.qb_selection_filter.append(self.ple.party_type == self.party_type)
|
|
||||||
|
|
||||||
self.add_common_filters(party_type_field=party_type_field)
|
self.add_common_filters(party_type_field=party_type_field)
|
||||||
|
|
||||||
if party_type_field == "customer":
|
if party_type_field == "customer":
|
||||||
self.add_customer_filters()
|
self.add_customer_filters()
|
||||||
|
|
||||||
elif party_type_field == "supplier":
|
elif party_type_field == "supplier":
|
||||||
self.add_supplier_filters()
|
self.add_supplier_filters()
|
||||||
|
|
||||||
if self.filters.cost_center:
|
if self.filters.cost_center:
|
||||||
self.get_cost_center_conditions()
|
self.get_cost_center_conditions()
|
||||||
@@ -791,11 +798,10 @@ class ReceivablePayableReport(object):
|
|||||||
self.qb_selection_filter.append(self.ple.account == self.filters.party_account)
|
self.qb_selection_filter.append(self.ple.account == self.filters.party_account)
|
||||||
else:
|
else:
|
||||||
# get GL with "receivable" or "payable" account_type
|
# get GL with "receivable" or "payable" account_type
|
||||||
account_type = "Receivable" if self.party_type == "Customer" else "Payable"
|
|
||||||
accounts = [
|
accounts = [
|
||||||
d.name
|
d.name
|
||||||
for d in frappe.get_all(
|
for d in frappe.get_all(
|
||||||
"Account", filters={"account_type": account_type, "company": self.filters.company}
|
"Account", filters={"account_type": self.account_type, "company": self.filters.company}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -885,7 +891,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
def get_party_details(self, party):
|
def get_party_details(self, party):
|
||||||
if not party in self.party_details:
|
if not party in self.party_details:
|
||||||
if self.party_type == "Customer":
|
if self.account_type == "Receivable":
|
||||||
fields = ["customer_name", "territory", "customer_group", "customer_primary_contact"]
|
fields = ["customer_name", "territory", "customer_group", "customer_primary_contact"]
|
||||||
|
|
||||||
if self.filters.get("sales_partner"):
|
if self.filters.get("sales_partner"):
|
||||||
@@ -921,7 +927,7 @@ class ReceivablePayableReport(object):
|
|||||||
width=180,
|
width=180,
|
||||||
)
|
)
|
||||||
self.add_column(
|
self.add_column(
|
||||||
label="Receivable Account" if self.party_type == "Customer" else "Payable Account",
|
label=self.account_type + " Account",
|
||||||
fieldname="party_account",
|
fieldname="party_account",
|
||||||
fieldtype="Link",
|
fieldtype="Link",
|
||||||
options="Account",
|
options="Account",
|
||||||
@@ -929,13 +935,19 @@ class ReceivablePayableReport(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.party_naming_by == "Naming Series":
|
if self.party_naming_by == "Naming Series":
|
||||||
|
if self.account_type == "Payable":
|
||||||
|
label = "Supplier Name"
|
||||||
|
fieldname = "supplier_name"
|
||||||
|
else:
|
||||||
|
label = "Customer Name"
|
||||||
|
fieldname = "customer_name"
|
||||||
self.add_column(
|
self.add_column(
|
||||||
_("{0} Name").format(self.party_type),
|
label=label,
|
||||||
fieldname=scrub(self.party_type) + "_name",
|
fieldname=fieldname,
|
||||||
fieldtype="Data",
|
fieldtype="Data",
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.party_type == "Customer":
|
if self.account_type == "Receivable":
|
||||||
self.add_column(
|
self.add_column(
|
||||||
_("Customer Contact"),
|
_("Customer Contact"),
|
||||||
fieldname="customer_primary_contact",
|
fieldname="customer_primary_contact",
|
||||||
@@ -955,7 +967,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
self.add_column(label="Due Date", fieldtype="Date")
|
self.add_column(label="Due Date", fieldtype="Date")
|
||||||
|
|
||||||
if self.party_type == "Supplier":
|
if self.account_type == "Payable":
|
||||||
self.add_column(label=_("Bill No"), fieldname="bill_no", fieldtype="Data")
|
self.add_column(label=_("Bill No"), fieldname="bill_no", fieldtype="Data")
|
||||||
self.add_column(label=_("Bill Date"), fieldname="bill_date", fieldtype="Date")
|
self.add_column(label=_("Bill Date"), fieldname="bill_date", fieldtype="Date")
|
||||||
|
|
||||||
@@ -965,7 +977,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
self.add_column(_("Invoiced Amount"), fieldname="invoiced")
|
self.add_column(_("Invoiced Amount"), fieldname="invoiced")
|
||||||
self.add_column(_("Paid Amount"), fieldname="paid")
|
self.add_column(_("Paid Amount"), fieldname="paid")
|
||||||
if self.party_type == "Customer":
|
if self.account_type == "Receivable":
|
||||||
self.add_column(_("Credit Note"), fieldname="credit_note")
|
self.add_column(_("Credit Note"), fieldname="credit_note")
|
||||||
else:
|
else:
|
||||||
# note: fieldname is still `credit_note`
|
# note: fieldname is still `credit_note`
|
||||||
@@ -983,7 +995,7 @@ class ReceivablePayableReport(object):
|
|||||||
self.add_column(label=_("Future Payment Amount"), fieldname="future_amount")
|
self.add_column(label=_("Future Payment Amount"), fieldname="future_amount")
|
||||||
self.add_column(label=_("Remaining Balance"), fieldname="remaining_balance")
|
self.add_column(label=_("Remaining Balance"), fieldname="remaining_balance")
|
||||||
|
|
||||||
if self.filters.party_type == "Customer":
|
if self.filters.account_type == "Receivable":
|
||||||
self.add_column(label=_("Customer LPO"), fieldname="po_no", fieldtype="Data")
|
self.add_column(label=_("Customer LPO"), fieldname="po_no", fieldtype="Data")
|
||||||
|
|
||||||
# comma separated list of linked delivery notes
|
# comma separated list of linked delivery notes
|
||||||
@@ -1004,7 +1016,7 @@ class ReceivablePayableReport(object):
|
|||||||
if self.filters.sales_partner:
|
if self.filters.sales_partner:
|
||||||
self.add_column(label=_("Sales Partner"), fieldname="default_sales_partner", fieldtype="Data")
|
self.add_column(label=_("Sales Partner"), fieldname="default_sales_partner", fieldtype="Data")
|
||||||
|
|
||||||
if self.filters.party_type == "Supplier":
|
if self.filters.account_type == "Payable":
|
||||||
self.add_column(
|
self.add_column(
|
||||||
label=_("Supplier Group"),
|
label=_("Supplier Group"),
|
||||||
fieldname="supplier_group",
|
fieldname="supplier_group",
|
||||||
|
|||||||
Reference in New Issue
Block a user