Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
5039 Vistas

Hello, I am writing a tool to import leads into our openerp instance.

The XMLRPC examples are very good, however I'm having trouble figuring out how to set the many2many_tags we need to tag the new lead with "New Lead".

xmlsock_common = xmlrpclib.ServerProxy(openerp_xmlrpcpath_common)
openerp_uid = xmlsock_common.login(
        openerp_dbname, openerp_username, openerp_password)

xmlsock_object = xmlrpclib.ServerProxy(openerp_xmlrpcpath_object)
    name =  '%s %s' % (wrapnone(message.pop("FirstName")),
            wrapnone(message.pop("LastName")))
    company = wrapnone(message.pop("Company"))
    title = "%s - %s - %s" % (company, name, wrapnone(message.pop("FormName", "unknownform")))
    #company name - contact name - FormName"

    lead = {
            'name': title,
            'partner_name': company,
            'contact_name': name,  # Contact Name
            'email_from': wrapnone(message.pop("EMail")),
            #'city': 'Santa Clara', # City
            'type': 'lead',
            'priority': '3',
            'description': notes,
            'phone': wrapnone(message.pop("Phone")),
            #'categ_ids': new_lead_ids,
            }

    xmlsock_object.execute(openerp_dbname, openerp_uid,
            openerp_password, 'crm.lead', 'create', lead)

The "field" I'm trying to set is:

Field: categ_ids
Object: crm.leads
Type: many2many
Widget: many2many_tags
Context: {'object_name': 'crm.lead'}
Domain: [('object_id.model','=','crm.lead')]
Relation: crm.case.categ

How can I look up "New Lead" in the "tags" table and set it on the new lead please?

Are there any examples using xmlrpc to fetch/set many2many2_tags I can use?

thank you, -Alfred

Avatar
Descartar
Mejor respuesta

You can search the id of 'New Lead" entry in the table crm.case.categ.

Once you have it, try :

lead = {
   [...]
   'categ_ids':  [(6,0,[newLead_id])],
   }
Avatar
Descartar
Autor

Sven, thank you !

Here is my query code:

# Query for 'New Lead' tag we need to assign.
print "Getting 'New Lead' id..."
args = [('categ', '=', 'New Lead')] #query clause
new_lead_ids = xmlsock_object.execute(
        openerp_dbname, openerp_uid, openerp_password,
        'crm.case', 'search', args)
print "done => %s" % new_lead_ids

However that seems to hang. Any ideas what I am doing wrong?

If you print new_lead_ids, what did you get ? Can you describe your crm.case table ? (what fields in ?)

Autor

Sven, thank you for your help. I finally figured out the fetch problem, my code incorrect, I was matching 'categ' = 'new lead' and using the wrong table 'crm.case' this is the fixed fetch code:

# Query for 'New Lead' tag we need to assign.
#print "Getting 'New Lead' id..."
#args = [('name', '=', 'New Lead')] #query clause
#new_lead_ids = xmlsock_object.execute(
    #    openerp_dbname, openerp_uid, openerp_password,
    #    'crm.case.categ', 'search', args)
#print "done => %s" % new_lead_ids

Thanks again for your help.

No problem. Can you close the question ? (With a [Closed] in the title.)

Autor Mejor respuesta

Sven answered my question. Closed.

Avatar
Descartar
Autor

done! thank you.

By the way, why don't the notification emails give me html link to the question I asked? Pretty frustrating.

Maybe some bug on the help.openerp.com :s

Publicaciones relacionadas Respuestas Vistas Actividad
1
sept 23
1775
2
nov 22
3358
4
oct 21
23658
4
oct 17
27970
2
jun 16
10993