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: show error message instead of throw during Purchase Invoice name validation (backport #2864) #2866

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
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 @@ -79,8 +79,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
29 changes: 16 additions & 13 deletions india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,23 +931,26 @@ def validate_invoice_number(doc, throw=True):
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:
frappe.throw(
_(
"Transaction Name must be 16 characters or fewer to meet GST requirements"
),
title=_("Invalid GST Transaction Name"),
message = _(
"Transaction Name must be 16 characters or fewer to meet GST requirements"
)

if not is_valid_format:
frappe.throw(
_(
"Transaction Name should start with an alphanumeric character and can"
" only contain alphanumeric characters, dash (-) and slash (/) to meet GST requirements"
),
title=_("Invalid GST Transaction Name"),
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)


def handle_server_errors(settings, doc, document_type, error):
if not doc.doctype == "Sales Invoice":
Expand Down
Loading