تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5142 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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?

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

الكاتب

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.)

الكاتب أفضل إجابة

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.

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
1882
2
نوفمبر 22
3498
4
أكتوبر 21
23883
4
أكتوبر 17
28153
2
يونيو 16
11140