This question has been flagged
1 Reply
4811 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?

Avatar
Discard
Best Answer

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.

Avatar
Discard