Odoo Help

0

Odoo10: Why is one2many field cannot be computed field???

By
Drees Far
on 10/12/17, 7:37 AM 175 views

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

0
Niyas Raphy
On 10/12/17, 8:04 AM

One2many field can be computed one. There is no restriction for it. In the above code, the name given for the compute and the functions name seems different. compute="_compute_attachment_case" try this

I am sorry that was a mistake in writting. I have corrected my post. what should be now the problem please need an answer

Drees Far
on 10/12/17, 8:05 AM

What is the error that you are getting ? i think you already have posted a same question right

Niyas Raphy
on 10/12/17, 8:07 AM

The function is calling but i do not have anything in the field nothing has been written :/

Drees Far
on 10/12/17, 8:09 AM

Please what does this mean ir.attachment(<odoo.models.NewId object at 0x7fdc03d87250>,)

Drees Far
on 10/12/17, 8:24 AM

There is no value in the self, that is why you are getting like this

Niyas Raphy
on 10/12/17, 8:27 AM

didnt understand but how to correct this ?? because the id was printed and its 21

Drees Far
on 10/12/17, 8:29 AM

See this code, this is used to write to one2many field inside a onchange function using self.update

for l in self.move_lines:

values.append(l.id)

vals = {

'name': product_id.partner_ref,

'product_id': product_id.id,

'product_uom_qty': 1,

'product_uom': product_id.uom_id.id,

'location_id': self.location_id.id,

'location_dest_id': self.location_dest_id.id,

}

line = self.env['stock.move'].create(vals)

values.append(line.id)

self.update({'move_lines': [(6, 0, values)]})

Niyas Raphy
on 10/12/17, 8:32 AM

what is values in this example

Drees Far
on 10/12/17, 8:38 AM

Empty list

Niyas Raphy
on 10/12/17, 8:41 AM

It doesnt work

Drees Far
on 10/12/17, 11:37 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 10/12/17, 7:37 AM
Seen: 175 times
Last updated: 10/12/17, 8:04 AM