diff --git a/addons/l10n_in_edi/models/account_edi_format.py b/addons/l10n_in_edi/models/account_edi_format.py index c350a051780..f35184b0b8d 100644 --- a/addons/l10n_in_edi/models/account_edi_format.py +++ b/addons/l10n_in_edi/models/account_edi_format.py @@ -199,6 +199,7 @@ class AccountEdiFormat(models.Model): error_codes = [e.get("code") for e in error] if "9999" in error_codes: response = {} + error = [] odoobot = self.env.ref("base.partner_root") invoice.message_post(author_id=odoobot.id, body=Markup(_( "Somehow this invoice had been cancelled to government before." \ @@ -212,7 +213,7 @@ class AccountEdiFormat(models.Model): "error": self._l10n_in_edi_get_iap_buy_credits_message(invoice.company_id), "blocking_level": "error", }} - else: + if error: error_message = "
".join(["[%s] %s" % (e.get("code"), html_escape(e.get("message"))) for e in error]) return {invoice: { "success": False, @@ -222,13 +223,15 @@ class AccountEdiFormat(models.Model): if not response.get("error"): json_dump = json.dumps(response.get("data", {})) json_name = "%s_cancel_einvoice.json" % (invoice.name.replace("/", "_")) - attachment = self.env["ir.attachment"].create({ - "name": json_name, - "raw": json_dump.encode(), - "res_model": "account.move", - "res_id": invoice.id, - "mimetype": "application/json", - }) + attachment = False + if json_dump: + attachment = self.env["ir.attachment"].create({ + "name": json_name, + "raw": json_dump.encode(), + "res_model": "account.move", + "res_id": invoice.id, + "mimetype": "application/json", + }) return {invoice: {"success": True, "attachment": attachment}} def _l10n_in_validate_partner(self, partner, is_company=False):