summaryrefslogtreecommitdiff
path: root/addons/account_edi/models/ir_attachment.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/account_edi/models/ir_attachment.py')
-rw-r--r--addons/account_edi/models/ir_attachment.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/addons/account_edi/models/ir_attachment.py b/addons/account_edi/models/ir_attachment.py
new file mode 100644
index 00000000..e49e6946
--- /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()