This question has been flagged

Hello everybody!!!

I am trying to create a computed one2many field.

Here is the declarations:

attachment_ids = fields.One2many('ir.attachment', 'attachment_case_id', string="Attachement", compute=_computed_field)

and the function is :

def _computed_field(self):

  for attachment in self :

   mail_ids = self.env['callim.mail'].search([('dossier_id','=',attachment.id)])

   if mail_ids :

    for mail in mail_ids :

     attachment_ids = self.env['ir.attachment'].search([('res_id','=', mail.id),('res_model','=','callim.mail')])

     current_case_id = self.id

     current_case_type = self.type_id.id

     if attachment_ids :

      for attach in attachment_ids[-1:]:

       attachment.write({'attachment_ids': [(0,0, {

         'attachment_case_id' : current_case_id,

         'datas' : attach.datas,

         'description' : attach.description,

          'type_id' : attach.type_id.id,

          'type_case' : current_case_type,

       })]})


Need Help please

Avatar
Discard