From bf1cb75ef1da926121325359edd11597350cdfc2 Mon Sep 17 00:00:00 2001 From: Surabhi Varma Date: Tue, 4 Apr 2023 09:42:57 +0000 Subject: [PATCH] [FIX] l10n_in_edi: fix bug If EDI is already cancelled then cancel invoice Before this commit ================== It was not allowed to cancel the invoice, an error message was displayed, response as False was returned as it was always moving inside else condition After this commit ================= After changes the error message has been removed and response as True is returned, and allowed to cancel the invoice task-3258582 closes odoo/odoo#151652 X-original-commit: 5a8826ec970dd87b203fdbc2214ac8381393ae2b Signed-off-by: Josse Colpaert Signed-off-by: Surabhi Varma (suva) --- .../l10n_in_edi/models/account_edi_format.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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):