| 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_ewaybill_government_document(self): |
| 10 | """ |
| 11 | Prevents the deletion of attachments related to government-issued documents. |
| 12 | """ |
| 13 | if any( |
| 14 | attachment.res_model == 'l10n.in.ewaybill' |
| 15 | and attachment.mimetype == 'application/json' |
| 16 | and attachment.res_field == 'attachment_file' |
| 17 | for attachment in self |
| 18 | ): |
| 19 | raise UserError(_("You can't unlink an attachment that you received from the government")) |