Hello Jürg Vogelsang,
In Odoo, when invoices are received by mail and processed into the Documents app, all attachments from the email (including small JPG/PNG images from signatures or marketing banners) are also created as ir.attachment records. This leads to unnecessary clutter in your incoming documents.
One way to solve this is by overriding the _message_post_process_attachments method to filter only the file types you want to keep (e.g., PDFs). Below is an example implementation:
def _message_post_process_attachments(self, attachments, attachment_ids, message_values):
# Run Odoo’s default behavior
attachment_data = super()._message_post_process_attachments(
attachments, attachment_ids, message_values
)
# Collect attachment IDs linked by M2M (command 4)
attachment_ids = [cmd[1] for cmd in attachment_data.get('attachment_ids', []) if cmd[0] == 4]
attachments = self.env['ir.attachment'].browse(attachment_ids)
# Keep only PDF files for documents
if message_values.get('model') == 'documents.document':
allowed_types = ['application/pdf']
attachments = attachments.filtered(lambda att: att.mimetype in allowed_types)
# Rebuild M2M list with filtered attachments
attachment_data['attachment_ids'] = [(4, att.id) for att in attachments]
return attachment_data
With this customization, only PDF invoices will be kept, while signature images like JPG/PNG will be ignored and not appear in your Documents list.
If you have any questions, feel free to reach out to us.
Hope this helps!
Thanks & Regards,
Email : odoo@aktivsoftware.com
Did you (or anyone else) find a solution to this ?
I'd be very interested in any solution!