Odoo Help

0

Pass values of a one2many field to another form?

By
ROSHAN
on 3/12/15, 2:04 AM 1,141 views

Hi

I have a class

class search_details(osv.osv):

    _description = 'Search Details'

    _name = 'search.details'
    
    def create_file(self, cr, uid, ids, context):
        opportunity_id = self.convert_to_file(cr, uid, ids, context=context)
        return self.pool.get('ip.local').view_file(cr, uid, opportunity_id, context)
    
    def convert_to_file(self, cr, uid, ids, partner_id=False, context=None):
        opportunity = self.pool.get('ip.local')
        for call in self.browse(cr, uid, ids, context=context):  

            class_id = call.classification_no_ids and call.classification_no_ids.id                          

            opportunity_id = opportunity.create(cr, uid, {
                            'classification_no_ids':class_id or False,
                            'search_date': call.search_date or False,
                            'search_slno': call.name,
                        })
       
            vals = {
                'file_no': opportunity_id,
            }
            self.write(cr, uid, [call.id], vals, context=context)

          return opportunity_id


            _columns = {
                        'name' : fields.integer('Sl No', readonly=True),
                        'search_date' : fields.date('Search Date'),             
                        'classification_no_ids' : fields.many2one('classification','Search Class No'),
                        'search_result': fields.one2many('search.name','name','Search Name'),
                        'file_no': fields.many2one ('ip.local', 'File No', readonly=True),
                        }

 

And i used a button create_file to createa new file in ip.local

What am trying is, to pass values from search.details to ip.local

am able to pass values of many2one,date and other kind of fields.

What am stuck with is l cannot pass the value in search_result which is an one2many field

How can i do it?

Please help

 

1
Emanuel Cino
On 3/12/15, 3:42 AM

If your class 'ip.local' has also a search_result field which is also of type one2many, you would do this the following:

 opportunity_id = opportunity.create(cr, uid, {
    'classification_no_ids':class_id or False,
    'search_date': call.search_date or False,
    'search_slno': call.name,
    'search_result': [(6, 0, [sr.id for sr in call.search_result])]

})

[(6, 0, ids)] is the standard way in Odoo to write into one2many fields.

thank you very much my friend

ROSHAN
on 3/12/15, 4:51 AM

it worked FANTASTICALLY

ROSHAN
on 3/12/15, 4:51 AM

Can you just tel me the link to get docs regarding this

ROSHAN
on 3/12/15, 4:53 AM

You can look this post for reference, but I cannot see where it is in documentation (Odoo is sometimes poorly documented) : https://www.odoo.com/forum/help-1/question/how-to-insert-value-to-a-one2many-field-in-table-with-create-method-28714

Emanuel Cino
on 3/12/15, 5:03 AM

Jst found a problem, the data is passing to other screen , its fine. But now the actual data gets deleted. How can i solve this?

ROSHAN
on 3/12/15, 6:39 AM

Ok, I am sorry I made a mistake in my answer. I will edit when we find the correct solution. Can you try with [(4, sr.id) for sr in call.search_result] instead of what I told you ?

Emanuel Cino
on 3/12/15, 7:29 AM

Or maybe the problem can come because of how you declare your field search_result : can you show me how it is declared in object ip.local ?

Emanuel Cino
on 3/13/15, 1:50 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: 3/12/15, 2:04 AM
Seen: 1141 times
Last updated: 3/16/15, 8:10 AM