From bb92b39bdccdeb082ca171f07d8d39d82983e9fd Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Tue, 15 Nov 2022 18:51:47 +0530 Subject: [PATCH] fix(pos): return: move amount check to pre submit Signed-off-by: Sabu Siyad --- .../accounts/doctype/pos_invoice/pos_invoice.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 54a3e934b2dc..0e0f00acded2 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -27,6 +27,13 @@ class POSInvoice(SalesInvoice): def __init__(self, *args, **kwargs): super(POSInvoice, self).__init__(*args, **kwargs) + def before_submit(self): + if self.is_return: + total_amount_in_payments = sum([entry.amount for entry in self.payments]) + invoice_total = self.rounded_total or self.grand_total + if total_amount_in_payments and total_amount_in_payments < invoice_total: + frappe.throw(_("Total payments amount can't be greater than {}").format(-invoice_total)) + def validate(self): if not cint(self.is_pos): frappe.throw( @@ -356,19 +363,12 @@ def validate_change_amount(self): frappe.msgprint(_("Please enter Account for Change Amount"), raise_exception=1) def validate_payment_amount(self): - total_amount_in_payments = 0 for entry in self.payments: - total_amount_in_payments += entry.amount if not self.is_return and entry.amount < 0: frappe.throw(_("Row #{0} (Payment Table): Amount must be positive").format(entry.idx)) if self.is_return and entry.amount > 0: frappe.throw(_("Row #{0} (Payment Table): Amount must be negative").format(entry.idx)) - if self.is_return: - invoice_total = self.rounded_total or self.grand_total - if total_amount_in_payments and total_amount_in_payments < invoice_total: - frappe.throw(_("Total payments amount can't be greater than {}").format(-invoice_total)) - def validate_loyalty_transaction(self): if self.redeem_loyalty_points and ( not self.loyalty_redemption_account or not self.loyalty_redemption_cost_center