Odoo Help

0

How to mimic autofill when importing via external script?

By
Mr. Kinjal Dixit
on 10/14/13, 7:47 AM 1,037 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=',')
        next(records)
        for record in records:
            print(record[0])

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

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

            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)

import_leads("./Leads.csv")

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.

Register

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)

Stats

Asked: 10/14/13, 7:47 AM
Seen: 1037 times
Last updated: 3/16/15, 8:10 AM