fix: Consider installments/partial payments while back updating Dunning
- Also use data from Overdue Payment table and not just Dunning parent document
This commit is contained in:
parent
4673aa412e
commit
254bab33da
@ -75,16 +75,12 @@ def resolve_dunning(doc, state):
|
|||||||
when a Payment Entry is submitted.
|
when a Payment Entry is submitted.
|
||||||
"""
|
"""
|
||||||
for reference in doc.references:
|
for reference in doc.references:
|
||||||
if reference.reference_doctype == "Sales Invoice" and reference.outstanding_amount <= 0:
|
# Consider partial and full payments
|
||||||
unresolved_dunnings = frappe.get_all(
|
if (
|
||||||
"Dunning",
|
reference.reference_doctype == "Sales Invoice"
|
||||||
filters={
|
and reference.outstanding_amount < reference.total_amount
|
||||||
"sales_invoice": reference.reference_name,
|
):
|
||||||
"status": ("!=", "Resolved"),
|
unresolved_dunnings = get_unresolved_dunnings(reference.reference_name)
|
||||||
"docstatus": ("!=", 2),
|
|
||||||
},
|
|
||||||
pluck="name",
|
|
||||||
)
|
|
||||||
|
|
||||||
for dunning_name in unresolved_dunnings:
|
for dunning_name in unresolved_dunnings:
|
||||||
resolve = True
|
resolve = True
|
||||||
@ -104,6 +100,23 @@ def resolve_dunning(doc, state):
|
|||||||
dunning.save()
|
dunning.save()
|
||||||
|
|
||||||
|
|
||||||
|
def get_unresolved_dunnings(sales_invoice):
|
||||||
|
dunning = frappe.qb.DocType("Dunning")
|
||||||
|
overdue_payment = frappe.qb.DocType("Overdue Payment")
|
||||||
|
|
||||||
|
return (
|
||||||
|
frappe.qb.from_(dunning)
|
||||||
|
.join(overdue_payment)
|
||||||
|
.on(overdue_payment.parent == dunning.name)
|
||||||
|
.select(dunning.name)
|
||||||
|
.where(
|
||||||
|
(dunning.status != "Resolved")
|
||||||
|
& (dunning.docstatus != 2)
|
||||||
|
& (overdue_payment.sales_invoice == sales_invoice)
|
||||||
|
)
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dunning_letter_text(dunning_type, doc, language=None):
|
def get_dunning_letter_text(dunning_type, doc, language=None):
|
||||||
if isinstance(doc, str):
|
if isinstance(doc, str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user