Skip to content

fix: strip whitespace and add more detailed error messages #80

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

Open
wants to merge 4 commits into
base: version-15
Choose a base branch
from

Conversation

MarcCon
Copy link
Collaborator

@MarcCon MarcCon commented Jun 30, 2025

Remove all whitespace from the VAT ID and improve error messages to show exactly which part is invalid.

e.g. an invalid number:

parse_vat_id("1DE3456")

ValueError: Invalid country code: 1D

Closes: #79

@MarcCon MarcCon requested a review from barredterra June 30, 2025 10:41
@barredterra
Copy link
Member

barredterra commented Jun 30, 2025

I think this function is a good candidate for adding some test cases, since it doesn't depend on the framework: #81

@barredterra
Copy link
Member

barredterra commented Jun 30, 2025

Reading the issue, my impression is that part of the suggested fix was also something like this (telling the user exactly which field caused the issue):

class VATIDCheck(Document):
	def before_insert(self):
+		try:
			country_code, vat_number = parse_vat_id(self.party_vat_id)
+		except ValueError:
+			frappe.throw(_("The VAT ID in {0} is invalid.").format(
+				_(self.meta.get_label("party_vat_id"))
+			)
		self.party_vat_id = f"{country_code}{vat_number}"

@barredterra barredterra linked an issue Jul 1, 2025 that may be closed by this pull request
* test: parse_vat_id

* ci: run pytest

* style: run pre-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Message not actionable
2 participants