Hey everyone,
I got two issues related to the res_model and res_id fields in ir.attachment.
1) In a custom module I am trying to add attachtments to a HTML field. However res_id in ir.attachments remains at value 0 for all tickets that I post.
For the attachments I copied the approach from the project module:
class Ticket(models.Model):
attachment_ids = fields.One2many('ir.attachment', compute='_compute_attachment_ids', string="Attachments", help="Attachment that don't come from message.")
def _compute_attachment_ids(self):
for ticket in self:
attachment_ids = self.env['ir.attachment'].search([('res_id', '=', ticket.id), ('res_model', '=', 'website.ticket')]).ids
message_attachment_ids = ticket.mapped('message_ids.attachment_ids').ids # from mail_thread
ticket.attachment_ids = list(set(attachment_ids) - set(message_attachment_ids))
But as res_id is not set correctly I do not get the correct number of attachments. When posting using mail.thread's Notes or document's Attach Files button res_id is set correctly.
2) The form view comes with additional TransientModels to send emails and post to the mail.thread. However I want all attachments, including mail.thread posts of those TransientModels, to show up in the Attach Files drop menu of the documents module. For this, I guess I need to set res_model to the main model and res_id to the TransientModels parent id.
E.g.:
class Ticket(models.Model):
_name = "ticket"
ticket-id = 3
class Ticket.Forward (models.TransientModels):
_name = "ticket.forward"
id = ticket-id = 3
Sadly I have no idea how to accomplish this. Help would be greatly appreciated.
Transient models cannot be used to store permanent data objects if you want that data you should use regular models