Files
odoo_source/addons/mail/models/ir_attachment.py
T
Olivier Colson 3c2a92e820 [IMP] mail: add main attachment support on mail.thread
This is done by adding a new field on mail.thread objects and setting it when posting a message with attachments on a model inheriting from mail.thread.

Was part of PR #26740
Was part of task #1880089
2018-09-14 17:29:49 +02:00

20 lines
743 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class IrAttachment(models.Model):
_inherit = 'ir.attachment'
def register_as_main_attachment(self):
""" Registers this attachment as the main one of the model it is
attached to.
"""
self.ensure_one()
related_record = self.env[self.res_model].browse(self.res_id)
# message_main_attachment_id field can be empty, that's why we compare to False;
# we are just checking that it exists on the model before writing it
if hasattr(related_record, 'message_main_attachment_id'):
related_record.message_main_attachment_id = self