fix: update set_advance_payment_status() logic

This commit is contained in:
Abdeali Chharchhoda
2024-07-22 17:21:57 +05:30
parent 4f0541dc16
commit cbed1d7826
3 changed files with 24 additions and 32 deletions

View File

@@ -1849,7 +1849,6 @@ def validate_inclusive_tax(tax, doc):
frappe.throw(_("Valuation type charges can not be marked as Inclusive"))
# todo: modify its test
@frappe.whitelist()
def get_outstanding_reference_documents(args, validate=False):
if isinstance(args, str):
@@ -2007,7 +2006,6 @@ def get_outstanding_reference_documents(args, validate=False):
)
)
return data

View File

@@ -272,10 +272,8 @@ class PaymentRequest(Document):
)
def set_as_paid(self):
self.db_set("status", "Paid")
if self.payment_channel == "Phone" and self.status != "Paid":
self.db_set("status", "Paid")
self.db_set({"status": "Paid", "outstanding_amount": 0})
else:
payment_entry = self.create_payment_entry()
@@ -304,8 +302,8 @@ class PaymentRequest(Document):
bank_amount = self.outstanding_amount
if party_account_currency == ref_doc.company_currency and party_account_currency != self.currency:
total = ref_doc.get("rounded_total") or ref_doc.get("grand_total")
base_total = ref_doc.get("base_rounded_total") or ref_doc.get("base_grand_total")
total = ref_doc.get("rounded_total") or ref_doc.grand_total
base_total = ref_doc.get("base_rounded_total") or ref_doc.base_grand_total
party_amount = flt(self.outstanding_amount / total * base_total, self.precision("grand_total"))
else:
party_amount = self.outstanding_amount
@@ -575,7 +573,6 @@ def get_existing_payment_request_amount(ref_dt, ref_dn, only_paid=False):
If `only_paid` is True, it will return the total amount of paid Payment Requests. \n
Else, it will return the total amount of all Payment Requests.
"""
PR = frappe.qb.DocType("Payment Request")
if only_paid:

View File

@@ -1944,35 +1944,32 @@ class AccountsController(TransactionBase):
self.set_advance_payment_status()
def set_advance_payment_status(self):
new_status = None
stati = frappe.get_all(
"Payment Request",
{
"reference_doctype": self.doctype,
"reference_name": self.name,
"docstatus": 1,
},
pluck="status",
from erpnext.accounts.doctype.payment_request.payment_request import (
get_existing_payment_request_amount as get_paid_amount,
)
if self.doctype in frappe.get_hooks("advance_payment_receivable_doctypes"):
if not stati:
new_status = None
available_payment_requests = frappe.db.count(
"Payment Request",
{"reference_doctype": self.doctype, "reference_name": self.name, "docstatus": 1},
)
total_amount = self.get("rounded_total") or self.grand_total
paid_amount = get_paid_amount(self.doctype, self.name, only_paid=True)
if paid_amount == total_amount:
new_status = "Fully Paid"
elif paid_amount > 0 and paid_amount < total_amount:
new_status = "Partially Paid"
elif self.doctype in frappe.get_hooks("advance_payment_receivable_doctypes"):
if not available_payment_requests:
new_status = "Not Requested"
elif "Requested" in stati or "Failed" in stati:
elif paid_amount == 0 or paid_amount == 0.0:
new_status = "Requested"
elif "Partially Paid" in stati:
new_status = "Partially Paid"
elif "Paid" in stati:
new_status = "Fully Paid"
if self.doctype in frappe.get_hooks("advance_payment_payable_doctypes"):
if not stati:
elif self.doctype in frappe.get_hooks("advance_payment_payable_doctypes"):
if not available_payment_requests:
new_status = "Not Initiated"
elif "Initiated" in stati or "Failed" in stati or "Payment Ordered" in stati:
elif paid_amount == 0 or paid_amount == 0.0:
new_status = "Initiated"
elif "Partially Paid" in stati:
new_status = "Partially Paid"
elif "Paid" in stati:
new_status = "Fully Paid"
if new_status == self.advance_payment_status:
return