콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
7535 화면

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

 

아바타
취소
베스트 답변

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

작성자

it worked FANTASTICALLY

작성자

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

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

작성자

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?

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 ?

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 ?