Odoo Help


Trouble importing state into res.partner

Chris Jones
on 8/29/13, 11:11 PM 2,363 views

I have a basic Python script that uses the xmlrpclib library to remotely create a customer in OpenERP 7.0.

customer = { 'comment': 'test notes', 'street2': None, 'phone': '605-730-1580', 'street': '24246 450th Ave', 'city': 'Pukwana', 'name': 'Karla Burns', 'zip': '57373', 'country': 'United States', 'Company': None, 'email': 'email@gmail.com', 'Active': 'TRUE', 'res.country.state': 'South Dakota', 'is_company': 'TRUE' } customer_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', customer)

The code runs fine and it creates the record but I can't get the State or Country to show up. The customer form is looking for res.partner.state_id and res.partner.country_id but those are integer fields and I don't know the int value for each state. How do I lookup the int of a state from res.country.state and feed it to res.partner.state_id?

martin mueller
On 9/20/13, 7:20 PM

You could use:

args = [('code', '=', 'US')] 
id = sock.execute(dbname, uid, pwd, 'res.country', 'search', args)

to get the id of the country and

args = [('code', '=', 'SD'), ('country_id', '=', 235)] 
id = sock.execute(dbname, uid, pwd, 'res.country.state', 'search', args)

to get the state id, then feed those into the customer data.

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.


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

0 follower(s)


Asked: 8/29/13, 11:11 PM
Seen: 2363 times
Last updated: 3/16/15, 8:10 AM