Merge pull request #33309 from barredterra/refactor-validate_payment_against_negative_invoice
refactor: translatable strings and guard clause
This commit is contained in:
commit
b7e9942681
@ -684,35 +684,34 @@ 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
|
||||||
|
additional_charges = sum(flt(d.amount) for d in self.deductions)
|
||||||
|
|
||||||
|
if not total_negative_outstanding:
|
||||||
|
if self.party_type == "Customer":
|
||||||
|
msg = _("Cannot pay to Customer without any negative outstanding invoice")
|
||||||
|
else:
|
||||||
|
msg = _("Cannot receive from Supplier without any negative outstanding invoice")
|
||||||
|
|
||||||
|
frappe.throw(msg, InvalidPaymentEntry)
|
||||||
|
|
||||||
|
elif paid_amount - additional_charges > total_negative_outstanding:
|
||||||
|
frappe.throw(
|
||||||
|
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
|
||||||
|
total_negative_outstanding
|
||||||
|
),
|
||||||
|
InvalidPaymentEntry,
|
||||||
)
|
)
|
||||||
|
|
||||||
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])
|
|
||||||
|
|
||||||
if not total_negative_outstanding:
|
|
||||||
frappe.throw(
|
|
||||||
_("Cannot {0} {1} {2} without any negative outstanding invoice").format(
|
|
||||||
_(self.payment_type),
|
|
||||||
(_("to") if self.party_type == "Customer" else _("from")),
|
|
||||||
self.party_type,
|
|
||||||
),
|
|
||||||
InvalidPaymentEntry,
|
|
||||||
)
|
|
||||||
|
|
||||||
elif paid_amount - additional_charges > total_negative_outstanding:
|
|
||||||
frappe.throw(
|
|
||||||
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
|
|
||||||
total_negative_outstanding
|
|
||||||
),
|
|
||||||
InvalidPaymentEntry,
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_title(self):
|
def set_title(self):
|
||||||
if frappe.flags.in_import and self.title:
|
if frappe.flags.in_import and self.title:
|
||||||
# do not set title dynamically if title exists during data import.
|
# do not set title dynamically if title exists during data import.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user