0
votes
_coloumns={'state_id': fields.many2one("res.country.state", 'State',required=True),
         'country_id': fields.many2one('res.country', 'Country',required=True),
       }  #  in my python file

# my xml file contains this code
<group col="4" colspan="4">
<field name="permanent_address" colspan="4"/>
<field name="birthday"/>
<!--<field name="department_id" on_change="onchange_department_id(department_id)"/>-->
<field name="unit"/>
<!--<field name="vertical_id"/>-->
<field name="gender"/>
<field name="city1"/>
<field name="state_id"/>
<field name="country_id"/>
<field name="mobile"/>
<field name="email"/>
<field name="blood_group"/>
<field name="pan_no"/>
<field name="marital"/>
<field name="anniversary_date" attrs="{'invisible':[('marital','!=','married')]}"/>
</group>

I need output like: `if i type state name(maharastra) in a field the country automatically filled with the country name (india)' enter code here

1

1 Answers

1
votes

The normal pattern would be:

  1. Add an on change method to the state_id field

    on_change="state_id_change(state_id, context)"
    
  2. Add the on change method to your model.

    def state_id_change(self, cr, uid, ids, state_id, context = None):
        values = {'country_id': False}
    
        if state_id:
            state = self.pool.get('state_model').browse(cr, uid, state_id, context = context)
            values['country_id'] = state.country_id.id
    
        return {'value': values}
    

Note that if they clear the state, this will also clear the country but if they select a state, it will look up the related country id and return it. You can put anything you want in the on_change as long as it returns a dictionary.

This assumes OpenERP 7. If you are on 6, leave the context argument out of the XML on_change attribute.

One last thing, you have a typo in your model, _columns is misspelled.