Odoo Help

Welcome!

This community 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.

2

How to load Child records to fields [Closed]

By
priyankahdp
on 3/27/13, 10:40 AM 4,153 views

The Question has been closed

by
priyankahdp
on 04/22/2013 04:58:54

here is my screen

Form Screen

and here is my code

link text

my requirement is like this.when i select a "division" from the above form, need to load relevant "workers" to my "selection workers area" (<notebook>area)

please advice me to implement that

=================================================================================== Dear Parth,

Now error is empty line comes and no data there..

I add this on line 217.please refer bpl.work.offer class

def onchange_division(self, cr, uid, ids, division_id, context=None):
    search_condition = [
                        ('bpl_division_id', '=', division_id)
                        ]
    w_ids = self.pool.get('bpl.worker').search(cr, uid , search_condition)
    list_of_dict = []
    for w_id in w_ids:
        list_of_dict.append({"selected_tea_workers_line_ids":w_id})
        return {'value': {"selected_tea_workers_line_ids":list_of_dict}}

==============================================================================

I entered this code for that function

def onchange_division(self, cr, uid, ids, division_id, context=None):
    search_condition = [
                        ('bpl_division_id', '=', division_id)
                        ]
    w_ids = self.pool.get('bpl.work.offer').search(cr, uid , search_condition)
    list_of_dict = []
    for w_id in w_ids:
        list_of_dict.append({"selected_tea_workers_line_ids":w_id})
        print (list_of_dict)

in my console it prints below two lines per two times. (i have added 2 records for work offer.going to load those details for that notebook section.)

[{'selected_tea_workers_line_ids': 3}]
[{'selected_tea_workers_line_ids': 3}, {'selected_tea_workers_line_ids': 5}]

but error comes as

TypeError: result is null

and no result return at the moment.

and dear Parth need to know why u added line like this.?

list_of_dict.append({"your worker one2many field name":w_id})

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dear Parth Issue sorted...

with the help of user1576199 (stackoverflow forum)

u also gives me a good guide

here is th code

def on_change_division(self, cr, uid, ids, division_id):
    v = {}
    list_data = []
    if division_id:
        worker_ids = self.pool.get('bpl.worker').search(cr, uid, [('bpl_division_id', '=', division_id)])
        for record in self.pool.get('bpl.worker').browse(cr, uid, worker_ids):
            list_data.append({'worker_id': record.id})
        v['selected_tea_workers_line_ids'] = list_data
        return {'value':v}

your worker one2many field name means your field name used in tree view ex: worker_id

and put return {'value': {"selected_tea_workers_line_ids":list_of_dict}} out of for loop

Parth Gajjar
on 3/29/13, 6:20 AM

yeah i added return one indent left>but no result friend

priyankahdp
on 3/29/13, 6:30 AM

list_of_dict.append({change here also:w_id})

return should be like this ....

return {'value': {"selected_tea_workers_line_ids": [{'worker_id': 3}, {'worker_ids': 5}] }}

In previous [{'worker_id': 3}, {'worker_ids': 5}] was list_of_dict

Parth Gajjar
on 3/29/13, 6:52 AM
1

Parth Gajjar

--Parth Gajjar--
1484
| 3 3 5
Ahmadabad, India
--Parth Gajjar--
Parth Gajjar
On 3/28/13, 10:14 AM

Return List of Dictionary In Onchange of your field

Inside your onchange_division function do this kind of thing

        //first pool your worker object
    w_ids=your_pooled_worker_object.search(cr, uid ,"your search condition")
    list_of_dict=[]
    for w_id in w_ids:
        list_of_dict.append({"your worker one2many field name":w_id})
    return {'value': {"selected_tea_workers_update_line_ids":list_of_dict}}

This will works 100% sure :p Hope this will work


Try This One

def on_change_division(self, cr, uid, ids, division_id, context=None):
    worker=self.pool.get("bpl.worker")
    worker_ids=worker.search(cr, uid, [("bpl_division_id","=", division_id)])
    list_of_dict=[]
    for worker_id in worker_ids:
        list_of_dict.append({"worker_id":worker_id})
    return {'value': {"selected_tea_workers_update_line_ids":list_of_dict}}

@parth, thanks Parth. i changed my function.but another error occur. can u please see my updated class & view.xml from this location & advice me to sort this out.. https://github.com/priyankahdp/openerp

[post updated]

priyankahdp
on 3/28/13, 10:51 AM
1

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/27/13, 11:06 AM

Try to return the following in your function onchange_division:

def onchange_division(self, cr, uid, ids, division_id, context=None):
    res = {}
    if division_id:
        res['domain'] = {'selected_tea_workers_line_ids': [('bpl_division_id','=', division_id)]}
    return res

For further information regarding the onchange functionality see the developer docu.

This sets a domain for field selected_tea_workers_line_ids in the view and the view should then limit the records according to this domain. But then the domain is only valid if you have changed the division explicitly. I am not 100% sure whether this works in your case but you can try it.

If it does not work you can take a look to the following question:

https://accounts.openerp.com/forum/Help-1/question/6602/

Thanks Andreas.i'm confused with how to code that in view.xml file.can give me a suggestion please

priyankahdp
on 3/27/13, 12:28 PM

You only have to update your onchange_division function, not the view.

Andreas Brueckl
on 3/27/13, 12:29 PM

then which field i need to map.? 'selected_tea_workers_line_ids' ?

priyankahdp
on 3/27/13, 1:19 PM

no error comes but data not loading friend

priyankahdp
on 3/27/13, 2:52 PM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/27/13, 10:40 AM
Seen: 4153 times
Last updated: 3/16/15, 8:10 AM