[FIX] account_edi: Prevent unlinking a EDI document sent to the government

X-original-commit: ea95f62af4faa23880e7c1f1cbe1aad3b2a490da
This commit is contained in:
Laurent Smet
2020-09-01 10:50:43 +00:00
parent 9d00341850
commit 5081999d52
2 changed files with 16 additions and 0 deletions
+1
View File
@@ -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
@@ -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()