[FIX] account: ensure attachment existence in mail attachments

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) <wan@odoo.com>
This commit is contained in:
aktr-odoo
2023-09-01 15:09:59 +00:00
parent f1e563f6b2
commit 0a44cd32cf
+1 -1
View File
@@ -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 {