mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
refactor(sales_invoice): replace sql with qb in check_if_reutrn_invoi… (#55374)
This commit is contained in:
@@ -3218,37 +3218,36 @@ def create_dunning(
|
|||||||
def check_if_return_invoice_linked_with_payment_entry(self):
|
def check_if_return_invoice_linked_with_payment_entry(self):
|
||||||
# If a Return invoice is linked with payment entry along with other invoices,
|
# If a Return invoice is linked with payment entry along with other invoices,
|
||||||
# the cancellation of the Return causes allocated amount to be greater than paid
|
# the cancellation of the Return causes allocated amount to be greater than paid
|
||||||
|
|
||||||
if not frappe.get_single_value("Accounts Settings", "unlink_payment_on_cancellation_of_invoice"):
|
if not frappe.get_single_value("Accounts Settings", "unlink_payment_on_cancellation_of_invoice"):
|
||||||
return
|
return
|
||||||
|
|
||||||
payment_entries = []
|
|
||||||
if self.is_return and self.return_against:
|
if self.is_return and self.return_against:
|
||||||
invoice = self.return_against
|
invoice = self.return_against
|
||||||
else:
|
else:
|
||||||
invoice = self.name
|
invoice = self.name
|
||||||
|
|
||||||
payment_entries = frappe.db.sql_list(
|
PaymentEntry = frappe.qb.DocType("Payment Entry")
|
||||||
"""
|
PaymentEntryReference = frappe.qb.DocType("Payment Entry Reference")
|
||||||
SELECT
|
|
||||||
t1.name
|
query = (
|
||||||
FROM
|
frappe.qb.from_(PaymentEntry)
|
||||||
`tabPayment Entry` t1, `tabPayment Entry Reference` t2
|
.join(PaymentEntryReference)
|
||||||
WHERE
|
.on(PaymentEntry.name == PaymentEntryReference.parent)
|
||||||
t1.name = t2.parent
|
.select(PaymentEntry.name)
|
||||||
and t1.docstatus = 1
|
.where(PaymentEntry.docstatus == 1)
|
||||||
and t2.reference_name = %s
|
.where(PaymentEntryReference.reference_name == invoice)
|
||||||
and t2.allocated_amount < 0
|
.where(PaymentEntryReference.allocated_amount < 0)
|
||||||
""",
|
|
||||||
invoice,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
payment_entries = query.run(pluck=True)
|
||||||
|
|
||||||
links_to_pe = []
|
links_to_pe = []
|
||||||
if payment_entries:
|
if payment_entries:
|
||||||
for payment in payment_entries:
|
for payment in payment_entries:
|
||||||
payment_entry = frappe.get_doc("Payment Entry", payment)
|
payment_entry = frappe.get_doc("Payment Entry", payment)
|
||||||
if len(payment_entry.references) > 1:
|
if len(payment_entry.references) > 1:
|
||||||
links_to_pe.append(payment_entry.name)
|
links_to_pe.append(payment_entry.name)
|
||||||
|
|
||||||
if links_to_pe:
|
if links_to_pe:
|
||||||
payment_entries_link = [
|
payment_entries_link = [
|
||||||
get_link_to_form("Payment Entry", name, label=name) for name in links_to_pe
|
get_link_to_form("Payment Entry", name, label=name) for name in links_to_pe
|
||||||
|
|||||||
Reference in New Issue
Block a user