Odoo Help


How to mimic autofill when importing via external script?

Mr. Kinjal Dixit
on 10/14/13, 7:47 AM 1,373 views

Update: I resolved this issue by setting the values during the import. So there is no urgency. However, I would like to know if I am doing this right.

I am importing leads using a python script. The import itself works great but the fields that get auto filled when I create a lead using the web client remain blank for the leads imported from the script. How do I mimic the auto fill action when importing using an external script. an excerpt from the script is pasted here. The lead shows up correctly in the web client. Just that the other values which get auto filled in the web client are blank. (the code works... it may give errors because it has been heavily redacted.)

import openerplib
import csv

def import_leads(csvfile):
    partner_model = connection.get_model('res.partner')
    lead_model = connection.get_model('crm.lead')
    user_model = connection.get_model('res.users')

    with open(csvfile, "rb") as csvfile:
        records = csv.reader(csvfile, delimiter=',')
        for record in records:

            # crmid fields are created in various models
            ids = lead_model.search([('crmid', '=', record[0])])
            if len(ids) > 0:

            ids = partner_model.search([('crmid', '=', record[2])])
            if len(ids) is 0:
                print("partner not found: " + record[2])

            partner_id = ids[0]

            from_user = record[19]    
            ids = user_model.search([('login', '=', from_user)])
            from_user_id = ids[0]

            lead = {
                'crmid': record[0],
                'partner_id': partner_id,
                'user_id': from_user_id,
                'crmid': record[0],
                'name': record[4]

            lead_id = lead_model.create(lead)
            # i think i have do something here like browse() or refresh() or something.

hostname = "localhost"
database = "test1"
login = "admin"
password = "admin"

connection = openerplib.get_connection(hostname=hostname,
    database=database, login=login, password=password)


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: 10/14/13, 7:47 AM
Seen: 1373 times
Last updated: 3/16/15, 8:10 AM