[FIX] account_edi: Prevent unlinking a EDI document sent to the government
X-original-commit: ea95f62af4faa23880e7c1f1cbe1aad3b2a490da
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user