[IMP] l10n_in_edi_ewaybill: don't send ewaybill if all lines are service

In this commit
=============================================
Before if all the lines were of service the error was displayed in a banner
after error in response was received, but now before sending request the lines
are checked if at least one line is of product and error is raised.

closes odoo/odoo#153816

X-original-commit: 251ee180ba0342f6a8c84d0a3ee93156a1cb06e0
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Surabhi Varma (suva) <suva@odoo.com>
This commit is contained in:
Surabhi Varma
2024-02-14 05:20:43 +00:00
parent 9d6e08296d
commit ca4edf83d4
@@ -98,6 +98,9 @@ class AccountEdiFormat(models.Model):
error_message.append(_("- Transport document number and date is required when Transportation Mode is Rail,Air or Ship"))
if error_message:
error_message.insert(0, _("The following information are missing on the invoice (see eWayBill tab):"))
goods_lines = move.invoice_line_ids.filtered(lambda line: not (line.display_type or line.is_rounding_line or line.product_id.type == "service"))
if not goods_lines:
error_message.append(_('You need at least one product having "Product Type" as stockable or consumable.'))
if base == "irn":
# already checked by E-invoice (l10n_in_edi) so no need to check
return error_message
@@ -107,9 +110,7 @@ class AccountEdiFormat(models.Model):
if not re.match("^.{1,16}$", is_purchase and move.ref or move.name):
error_message.append(_("%s number should be set and not more than 16 characters",
(is_purchase and "Bill Reference" or "Invoice")))
goods_line_is_available = False
for line in move.invoice_line_ids.filtered(lambda line: not (line.display_type in ('line_section', 'line_note', 'rounding') or line.product_id.type == "service")):
goods_line_is_available = True
for line in goods_lines:
if line.product_id:
hsn_code = self._l10n_in_edi_extract_digits(line.product_id.l10n_in_hsn_code)
if not hsn_code:
@@ -120,8 +121,6 @@ class AccountEdiFormat(models.Model):
))
else:
error_message.append(_("product is required to get HSN code"))
if not goods_line_is_available:
error_message.append(_('You need at least one product having "Product Type" as stockable or consumable.'))
if error_message:
error_message.insert(0, _("Impossible to send the Ewaybill."))
return error_message