perf: search for customer's return invoices then filter out gl_entries (#20709)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
Saqib
2020-02-26 11:36:55 +05:30
committed by GitHub
parent 7229f694ea
commit 3957ac1408
2 changed files with 15 additions and 6 deletions

View File

@@ -92,6 +92,7 @@ class PaymentReconciliation(Document):
FROM `tab{doc}`, `tabGL Entry` FROM `tab{doc}`, `tabGL Entry`
WHERE WHERE
(`tab{doc}`.name = `tabGL Entry`.against_voucher or `tab{doc}`.name = `tabGL Entry`.voucher_no) (`tab{doc}`.name = `tabGL Entry`.against_voucher or `tab{doc}`.name = `tabGL Entry`.voucher_no)
and `tab{doc}`.{party_type_field} = %(party)s
and `tab{doc}`.is_return = 1 and `tab{doc}`.return_against IS NULL and `tab{doc}`.is_return = 1 and `tab{doc}`.return_against IS NULL
and `tabGL Entry`.against_voucher_type = %(voucher_type)s and `tabGL Entry`.against_voucher_type = %(voucher_type)s
and `tab{doc}`.docstatus = 1 and `tabGL Entry`.party = %(party)s and `tab{doc}`.docstatus = 1 and `tabGL Entry`.party = %(party)s
@@ -99,12 +100,17 @@ class PaymentReconciliation(Document):
GROUP BY `tab{doc}`.name GROUP BY `tab{doc}`.name
Having Having
amount > 0 amount > 0
""".format(doc=voucher_type, dr_or_cr=dr_or_cr, reconciled_dr_or_cr=reconciled_dr_or_cr), { """.format(
'party': self.party, doc=voucher_type,
'party_type': self.party_type, dr_or_cr=dr_or_cr,
'voucher_type': voucher_type, reconciled_dr_or_cr=reconciled_dr_or_cr,
'account': self.receivable_payable_account party_type_field=frappe.scrub(self.party_type)),
}, as_dict=1) {
'party': self.party,
'party_type': self.party_type,
'voucher_type': voucher_type,
'account': self.receivable_payable_account
}, as_dict=1)
def add_payment_entries(self, entries): def add_payment_entries(self, entries):
self.set('payments', []) self.set('payments', [])

View File

@@ -1548,6 +1548,9 @@ def get_loyalty_programs(customer):
else: else:
return lp_details return lp_details
def on_doctype_update():
frappe.db.add_index("Sales Invoice", ["customer", "is_return", "return_against"])
@frappe.whitelist() @frappe.whitelist()
def create_invoice_discounting(source_name, target_doc=None): def create_invoice_discounting(source_name, target_doc=None):
invoice = frappe.get_doc("Sales Invoice", source_name) invoice = frappe.get_doc("Sales Invoice", source_name)