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

[closed] help with xmlrpc + many2many_tags

By
Alfred Perlstein
on 8/11/13, 6:14 PM 1,497 views

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

1
Xsias
On 8/12/13, 7:47 AM

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])],
   }

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?

Alfred Perlstein
on 8/12/13, 10:01 AM

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

Xsias
on 8/12/13, 10:12 AM

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.

Alfred Perlstein
on 8/12/13, 1:37 PM

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

Xsias
on 8/13/13, 9:46 AM
0
Alfred Perlstein
On 8/13/13, 11:19 AM

Sven answered my question. Closed.

done! thank you.

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

Alfred Perlstein
on 8/13/13, 11:38 AM

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

Xsias
on 8/13/13, 1:43 PM

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

1 follower(s)

Stats

Asked: 8/11/13, 6:14 PM
Seen: 1497 times
Last updated: 3/16/15, 8:10 AM