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

Not handling Company Tax ID field on submission of Sales Invoice for Italian E-Invoicing #45295

Open
rahib-hassan opened this issue Jan 16, 2025 · 0 comments
Labels

Comments

@rahib-hassan
Copy link
Contributor

rahib-hassan commented Jan 16, 2025

Information about bug

Adding an Issue and not a PR since I am unsure about the legal side.

Issue

Image

In the current implementation of e-invoicing for Italy, the company_tax_id is not being handled properly.
https://github.com/frappe/erpnext/blob/43ce185429ad125d76379e5a98179181627e2d8e/erpnext/regional/italy/utils.py#L264

In the sales_invoice_validate() method, an error is thrown only if both company_tax_id and company_fiscal_code are missing. This allows invoices to proceed if at least one of these fields is set. and in the get_progressive_name_and_number() method, the company_tax_id is accessed without a fallback mechanism, leading to runtime errors if it is not set.

if not doc.company_tax_id and not doc.company_fiscal_code:
	frappe.throw(
		_("Please set either the Tax ID or Fiscal Code on Company '%s'" % doc.company),
		title=_("E-Invoicing Information Missing"),
	)

https://github.com/frappe/erpnext/blob/43ce185429ad125d76379e5a98179181627e2d8e/erpnext/regional/italy/utils.py#L469

company_tax_id = doc.company_tax_id if doc.company_tax_id.startswith("IT") else "IT" + doc.company_tax_id

Steps to Reproduce:

  1. Create a company in the Italian regional setup without setting a tax_id but with a fiscal_code.
  2. Create a sales invoice for this company.
  3. Validation does not raise any error in sales_invoice_validate() since the fiscal_code is set.
  4. During submission of the sales invoice it triggers get_progressive_name_and_number() method.
  5. A runtime error occurs because company_tax_id is accessed directly without checking its existence.

Suggested Solution

  1. Throw an error if company_tax_id is not present during validation.
  2. Handle get_progressive_name_and_number() method by including either company_fiscal_code or tax_id
company_tax_id = doc.company_tax_id if doc.company_tax_id and doc.company_tax_id.startswith("IT") else "IT" + (doc.company_tax_id or doc.tax_id)
if not company_tax_id:
    frappe.throw(
        _("Company Tax ID is required to generate the progressive name."),
        title=_("Missing Information")
    )

Module

regional

Version

Frappe Version - Version-15
ERPNext Version - Version-15

Installation method

None

Relevant log output / Stack trace / Full Error Message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant