From 0a44cd32cf22f178c5a590f48d534d71219ac8d4 Mon Sep 17 00:00:00 2001 From: aktr-odoo Date: Thu, 24 Aug 2023 10:49:41 +0000 Subject: [PATCH] [FIX] account: ensure attachment existence in mail attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The traceback arises when a user deletes an attachment that the referenced in the `account.move.send` model's `mail_attachments_widget` field, and subsequently, the cron uses `mail_attachments_widget` to send invoices. Steps to produce: - Install account. - Open Invoicing > open any invoice > click on SEND & PRINT > click on SAVE. - Add an attachment > refresh the page. - Go to attachments > delete the attachment which you have uploaded. - Let the cron `Send invoices automatically ` run automatically. ERROR: Traceback will appear MissingError Record does not exist or has been deleted. A `mail_attachments_widget` is a `JSON`storable field (Line 1) of the `account.move.send` model. `mail_attachments_widget` carries data like the attachment's ID, name, and mime type. Cron utilized the `mail_attachments_widget` field to retrieve attachment data when sending an email with attachments. `seen_attachment_ids` is a list of IDs (Line 2) of attachments prepared using `mail_attachments_widget`. This commit fetches only existing attachment records from the 'ir.attachment' model for the attachment IDs present in the `seen_attachment_ids` list. Line [1]- https://github.com/odoo/odoo/blob/0c95e064ca6384f57154bb12d3b4ef55ee1b4da3/addons/account/wizard/account_move_send.py#L76-L80 Line [2]- https://github.com/odoo/odoo/blob/d87dc624c33c8edd0eafc130b02a95fd91e58094/addons/account/wizard/account_move_send.py#L433-L439 Sentry-4315708399 closes odoo/odoo#133951 X-original-commit: 2486300538bc68075cba530bec481909af1aeb0d Signed-off-by: William André (wan) --- addons/account/wizard/account_move_send.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/wizard/account_move_send.py b/addons/account/wizard/account_move_send.py index 1b959a67655..21403052b71 100644 --- a/addons/account/wizard/account_move_send.py +++ b/addons/account/wizard/account_move_send.py @@ -467,7 +467,7 @@ class AccountMoveSend(models.Model): mail_attachments = [ (attachment.name, attachment.raw) - for attachment in self.env['ir.attachment'].browse(list(seen_attachment_ids)) + for attachment in self.env['ir.attachment'].browse(list(seen_attachment_ids)).exists() ] return {