Debian Codegraph @

addons/l10n_in_edi/models/ir_attachment.py

raw
1 from odoo import api, models
2 from odoo.exceptions import UserError
3
4
5 class IrAttachment(models.Model):
6 _inherit = 'ir.attachment'
7
8 @api.ondelete(at_uninstall=False)
9 def _unlink_except_l10n_in_government_document(self):
10 """
11 Prevents the deletion of attachments related to government-issued documents.
12 """
13 if any(
14 attachment.res_model == 'account.move'
15 and attachment.mimetype == 'application/json'
16 and attachment.res_field == 'l10n_in_edi_attachment_file'
17 for attachment in self
18 ):
19 raise UserError(self.env._(
20 "You can't unlink an attachment that you received from the government"
21 ))