Skip to content

Commit

Permalink
fix: show error message instead of throw during Purchase Invoice name…
Browse files Browse the repository at this point in the history
… validation (#2864)

* fix: show error message instead of throw

* fix: for purchase invoice use msgprint instead of throw

* test: minor change in test case

* fix: resolve test case for sales invoice

---------

Co-authored-by: Sanket322 <shahsanket322003.com>
(cherry picked from commit a8e5490)

# Conflicts:
#	india_compliance/gst_india/utils/__init__.py
  • Loading branch information
Sanket322 authored and mergify[bot] committed Dec 13, 2024
1 parent 298fd9a commit 703c0b5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 4 additions & 3 deletions india_compliance/gst_india/overrides/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def test_validate_invoice_length(self):
setattr(pinv, "__newname", "INV/2022/00001/asdfsadg") # NOQA
pinv.meta.autoname = "prompt"

self.assertRaisesRegex(
frappe.exceptions.ValidationError,
pinv.save()

self.assertEqual(
frappe.parse_json(frappe.message_log[-1]).get("message"),
"Transaction Name must be 16 characters or fewer to meet GST requirements",
pinv.save,
)
4 changes: 3 additions & 1 deletion india_compliance/gst_india/overrides/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def test_validate_invoice_number(self):
"PI2021 - 001",
]
for name in invalid_names:
doc = frappe._dict(name=name, posting_date=posting_date)
doc = frappe._dict(
name=name, posting_date=posting_date, doctype="Sales Invoice"
)
self.assertRaises(frappe.ValidationError, validate_invoice_number, doc)

valid_names = [
Expand Down
28 changes: 28 additions & 0 deletions india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ def disable_item_tax_template_notification():
def validate_invoice_number(doc):
"""Validate GST invoice number requirements."""

<<<<<<< HEAD
if len(doc.name) > 16:
frappe.throw(
_(
Expand All @@ -935,6 +936,33 @@ def validate_invoice_number(doc):
),
title=_("Invalid GST Transaction Name"),
)
=======
is_valid_length = len(doc.name) <= 16
is_valid_format = GST_INVOICE_NUMBER_FORMAT.match(doc.name)

if not throw:
return is_valid_length and is_valid_format

if is_valid_length and is_valid_format:
return

title = _("Invalid GST Transaction Name")

if not is_valid_length:
message = _(
"Transaction Name must be 16 characters or fewer to meet GST requirements"
)
else:
message = _(
"Transaction Name should start with an alphanumeric character and can"
" only contain alphanumeric characters, dash (-) and slash (/) to meet GST requirements"
)

if doc.doctype == "Sales Invoice":
frappe.throw(message, title=title)

frappe.msgprint(message, title=title)
>>>>>>> a8e54900 (fix: show error message instead of throw during Purchase Invoice name validation (#2864))


def handle_server_errors(settings, doc, document_type, error):
Expand Down

0 comments on commit 703c0b5

Please sign in to comment.