[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 <jco@odoo.com>
Signed-off-by: Surabhi Varma (suva) <suva@odoo.com>
This commit is contained in:
Surabhi Varma
2024-01-30 12:20:00 +00:00
parent 215b61f6b6
commit bf1cb75ef1
@@ -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 = "<br/>".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):