fix: Validate negative allocated amount in Payment Entry (#25799)

This commit is contained in:
Deepesh Garg 2021-06-09 17:56:41 +05:30 committed by GitHub
parent bf5f87c2fe
commit b57ebba3fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View File

@ -49,11 +49,11 @@ class InvoiceDiscounting(AccountsController):
self.make_gl_entries() self.make_gl_entries()
def on_cancel(self): def on_cancel(self):
self.set_status() self.set_status(cancel=1)
self.update_sales_invoice() self.update_sales_invoice()
self.make_gl_entries() self.make_gl_entries()
def set_status(self, status=None): def set_status(self, status=None, cancel=0):
if status: if status:
self.status = status self.status = status
self.db_set("status", status) self.db_set("status", status)
@ -66,6 +66,9 @@ class InvoiceDiscounting(AccountsController):
elif self.docstatus == 2: elif self.docstatus == 2:
self.status = "Cancelled" self.status = "Cancelled"
if cancel:
self.db_set('status', self.status, update_modified = True)
def update_sales_invoice(self): def update_sales_invoice(self):
for d in self.invoices: for d in self.invoices:
if self.docstatus == 1: if self.docstatus == 1:

View File

@ -65,7 +65,6 @@ class PaymentEntry(AccountsController):
self.set_status() self.set_status()
def on_submit(self): def on_submit(self):
self.setup_party_account_field()
if self.difference_amount: if self.difference_amount:
frappe.throw(_("Difference Amount must be zero")) frappe.throw(_("Difference Amount must be zero"))
self.make_gl_entries() self.make_gl_entries()
@ -78,7 +77,6 @@ class PaymentEntry(AccountsController):
def on_cancel(self): def on_cancel(self):
self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry')
self.setup_party_account_field()
self.make_gl_entries(cancel=1) self.make_gl_entries(cancel=1)
self.update_outstanding_amounts() self.update_outstanding_amounts()
self.update_advance_paid() self.update_advance_paid()
@ -122,6 +120,11 @@ class PaymentEntry(AccountsController):
if flt(d.allocated_amount) > flt(d.outstanding_amount): if flt(d.allocated_amount) > flt(d.outstanding_amount):
frappe.throw(_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx)) frappe.throw(_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx))
# Check for negative outstanding invoices as well
if flt(d.allocated_amount) < 0:
if flt(d.allocated_amount) < flt(d.outstanding_amount):
frappe.throw(_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx))
def delink_advance_entry_references(self): def delink_advance_entry_references(self):
for reference in self.references: for reference in self.references:
if reference.reference_doctype in ("Sales Invoice", "Purchase Invoice"): if reference.reference_doctype in ("Sales Invoice", "Purchase Invoice"):
@ -177,7 +180,7 @@ class PaymentEntry(AccountsController):
for field, value in iteritems(ref_details): for field, value in iteritems(ref_details):
if field == 'exchange_rate' or not d.get(field) or force: if field == 'exchange_rate' or not d.get(field) or force:
d.set(field, value) d.db_set(field, value)
def validate_payment_type(self): def validate_payment_type(self):
if self.payment_type not in ("Receive", "Pay", "Internal Transfer"): if self.payment_type not in ("Receive", "Pay", "Internal Transfer"):
@ -386,6 +389,8 @@ class PaymentEntry(AccountsController):
else: else:
self.status = 'Draft' self.status = 'Draft'
self.db_set('status', self.status, update_modified = True)
def set_amounts(self): def set_amounts(self):
self.set_amounts_in_company_currency() self.set_amounts_in_company_currency()
self.set_total_allocated_amount() self.set_total_allocated_amount()
@ -791,7 +796,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices):
outstanding_invoices.pop(idx - 1) outstanding_invoices.pop(idx - 1)
outstanding_invoices += invoice_ref_based_on_payment_terms[idx] outstanding_invoices += invoice_ref_based_on_payment_terms[idx]
return outstanding_invoices return outstanding_invoices
def get_orders_to_be_billed(posting_date, party_type, party, def get_orders_to_be_billed(posting_date, party_type, party,
@ -989,6 +994,7 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
outstanding_amount = ref_doc.get("outstanding_amount") outstanding_amount = ref_doc.get("outstanding_amount")
elif reference_doctype == "Donation": elif reference_doctype == "Donation":
total_amount = ref_doc.get("amount") total_amount = ref_doc.get("amount")
outstanding_amount = total_amount
exchange_rate = 1 exchange_rate = 1
elif reference_doctype == "Dunning": elif reference_doctype == "Dunning":
total_amount = ref_doc.get("dunning_amount") total_amount = ref_doc.get("dunning_amount")

View File

@ -101,7 +101,7 @@ class PaymentRequest(Document):
controller.validate_transaction_currency(self.currency) controller.validate_transaction_currency(self.currency)
controller.request_for_payment(**payment_record) controller.request_for_payment(**payment_record)
def get_request_amount(self): def get_request_amount(self):
data_of_completed_requests = frappe.get_all("Integration Request", filters={ data_of_completed_requests = frappe.get_all("Integration Request", filters={
'reference_doctype': self.doctype, 'reference_doctype': self.doctype,
@ -492,7 +492,6 @@ def update_payment_req_status(doc, method):
status = 'Requested' status = 'Requested'
pay_req_doc.db_set('status', status) pay_req_doc.db_set('status', status)
frappe.db.commit()
def get_dummy_message(doc): def get_dummy_message(doc):
return frappe.render_template("""{% if doc.contact_person -%} return frappe.render_template("""{% if doc.contact_person -%}

View File

@ -584,6 +584,7 @@ class ReceivablePayableReport(object):
`tabGL Entry` `tabGL Entry`
where where
docstatus < 2 docstatus < 2
and is_cancelled = 0
and party_type=%s and party_type=%s
and (party is not null and party != '') and (party is not null and party != '')
{1} {2} {3}""" {1} {2} {3}"""