Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: submit POS Invoice only if the invoice amount is fully paid #43966

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions erpnext/accounts/doctype/pos_invoice/pos_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos


class PaymentValidationError(frappe.ValidationError):
pass


class POSInvoice(SalesInvoice):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.
Expand Down Expand Up @@ -452,11 +456,20 @@ def validate_payment_amount(self):
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 and self.docstatus != 0:
invoice_total = self.rounded_total or self.grand_total
total_amount_in_payments = flt(total_amount_in_payments, self.precision("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))
invoice_total = self.rounded_total or self.grand_total
total_amount_in_payments = flt(total_amount_in_payments, self.precision("grand_total"))

if self.docstatus != 0 and total_amount_in_payments and total_amount_in_payments < invoice_total:
if self.is_return:
frappe.throw(
_("Total payments amount can't be greater than {}").format(-invoice_total),
PaymentValidationError,
)
else:
frappe.throw(
_("Total payments amount can't be less than {}").format(invoice_total),
PaymentValidationError,
)

def validate_company_with_pos_company(self):
if self.company != frappe.db.get_value("POS Profile", self.pos_profile, "company"):
Expand Down
9 changes: 8 additions & 1 deletion erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from frappe import _
from frappe.tests import IntegrationTestCase

from erpnext.accounts.doctype.pos_invoice.pos_invoice import make_sales_return
from erpnext.accounts.doctype.pos_invoice.pos_invoice import PaymentValidationError, make_sales_return
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.stock.doctype.item.test_item import make_item
Expand Down Expand Up @@ -933,6 +933,13 @@ def test_delivered_serial_no_case(self):
frappe.db.rollback(save_point="before_test_delivered_serial_no_case")
frappe.set_user("Administrator")

def test_validate_paid_amount(self):
inv = create_pos_invoice(qty=10, rate=5, do_not_save=True)
inv.payments = []
inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 45})
inv.insert()
self.assertRaises(PaymentValidationError, inv.submit)


def create_pos_invoice(**args):
args = frappe._dict(args)
Expand Down
Loading