From 5081999d522c767a610bbb6645a2979fbf5b8c15 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Mon, 31 Aug 2020 14:42:41 +0000 Subject: [PATCH] [FIX] account_edi: Prevent unlinking a EDI document sent to the government X-original-commit: ea95f62af4faa23880e7c1f1cbe1aad3b2a490da --- addons/account_edi/models/__init__.py | 1 + addons/account_edi/models/ir_attachment.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 addons/account_edi/models/ir_attachment.py diff --git a/addons/account_edi/models/__init__.py b/addons/account_edi/models/__init__.py index e2229d0dd2f..1d924dbdbb4 100644 --- a/addons/account_edi/models/__init__.py +++ b/addons/account_edi/models/__init__.py @@ -7,3 +7,4 @@ from . import account_edi_document from . import account_payment from . import ir_actions_report from . import mail_template +from . import ir_attachment diff --git a/addons/account_edi/models/ir_attachment.py b/addons/account_edi/models/ir_attachment.py new file mode 100644 index 00000000000..e49e6946576 --- /dev/null +++ b/addons/account_edi/models/ir_attachment.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, _ +from odoo.exceptions import UserError + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + def unlink(self): + # OVERRIDE + linked_edi_documents = self.env['account.edi.document'].search([('attachment_id', 'in', self.ids)]) + linked_edi_formats_ws = linked_edi_documents.edi_format_id.filtered(lambda edi_format: edi_format._needs_web_services()) + if linked_edi_formats_ws: + raise UserError(_("You can't unlink an attachment being an EDI document sent to the government.")) + return super().unlink()