Merge pull request #33309 from barredterra/refactor-validate_payment_against_negative_invoice

refactor: translatable strings and guard clause
This commit is contained in:
Deepesh Garg 2022-12-15 09:21:16 +05:30 committed by GitHub
commit b7e9942681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -684,26 +684,25 @@ class PaymentEntry(AccountsController):
) )
def validate_payment_against_negative_invoice(self): def validate_payment_against_negative_invoice(self):
if (self.payment_type == "Pay" and self.party_type == "Customer") or ( if (self.payment_type != "Pay" or self.party_type != "Customer") and (
self.payment_type == "Receive" and self.party_type == "Supplier" self.payment_type != "Receive" or self.party_type != "Supplier"
): ):
return
total_negative_outstanding = sum( total_negative_outstanding = sum(
abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0 abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0
) )
paid_amount = self.paid_amount if self.payment_type == "Receive" else self.received_amount paid_amount = self.paid_amount if self.payment_type == "Receive" else self.received_amount
additional_charges = sum([flt(d.amount) for d in self.deductions]) additional_charges = sum(flt(d.amount) for d in self.deductions)
if not total_negative_outstanding: if not total_negative_outstanding:
frappe.throw( if self.party_type == "Customer":
_("Cannot {0} {1} {2} without any negative outstanding invoice").format( msg = _("Cannot pay to Customer without any negative outstanding invoice")
_(self.payment_type), else:
(_("to") if self.party_type == "Customer" else _("from")), msg = _("Cannot receive from Supplier without any negative outstanding invoice")
self.party_type,
), frappe.throw(msg, InvalidPaymentEntry)
InvalidPaymentEntry,
)
elif paid_amount - additional_charges > total_negative_outstanding: elif paid_amount - additional_charges > total_negative_outstanding:
frappe.throw( frappe.throw(