Odoo Help

Welcome!

This community 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.

0

How to mimic autofill when importing via external script?

By
Mr. Kinjal Dixit
on 10/14/13, 7:47 AM 973 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")

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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