| 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=True) |
| 9 | def _except_submitted_invoices_pdfs(self): |
| 10 | submitted_invoices_pdfs = self.filtered( |
| 11 | lambda attachment: |
| 12 | attachment.res_model == 'account.move' |
| 13 | and attachment.res_id |
| 14 | and attachment.res_field == 'invoice_pdf_report_file' |
| 15 | ) |
| 16 | |
| 17 | moves = self.env['account.move'].browse(submitted_invoices_pdfs.mapped('res_id')).exists() |
| 18 | moves_with_jo_qr = moves.filtered('l10n_jo_edi_qr') |
| 19 | if moves_with_jo_qr: |
| 20 | raise UserError(_("You cannot delete this Invoice PDF as it has been submitted to JoFotara")) |