Question

It seems onchange method only works on current visible fields. If I use it to fill other fields that are in other pages of the view, it does not do anything. For example I have view with many pages. Mainly all information needs to be filled in first page, so most fields are filled correctly. But there is one field I need to fill in other page, when I choose partner_id in another page. For example in view like this:

...
<page string="page1">
  <field name=partner_id on_change="onchange_partner(partner_id)"
  <field name="field1"/>
  <field name="field2"/>

</page>
<page string="page2">
   <field name="field3"/>
</page>
...

field1 and field2 will be filled. But how to fill field3 or is it impossible, because system do not save it into database using onchange method?

My onchange method looks something like this:

def onchange_partner(self, cr, uid, ids, partner_id, context=None):
  res = {}
  if partner_id:
    obj = self.pool.get('res.partner').browse(cr, uid, partner_id)
    res['field1'] = obj.field1
    res['field2'] = obj.field2
    res['field3'] = obj.field3 # this value isn't being filled
  return {'value': res}

So how could I fill field3?

Was it helpful?

Solution

Its not like that. It will definitely change the value. you might not be getting value in field3 because the record you are fetching will not have value of field3. and answer to your question is IT WORKS. Try this,

def onchange_partner(self, cr, uid, ids, partner_id, context=None):
    res = {}
    if partner_id:
        obj = self.pool.get('res.partner').browse(cr, uid, partner_id)
        res['field1'] = obj.field1
        res['field2'] = obj.field2
        res['field3'] = 'Hello' # this field type must be char or if not then give 
        #value accordingly, its just to prove you that values are filled on onchange.
    return {'value': res}

Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top