简体   繁体   中英

Odoo 10 - XMLRPC - Use external XML identifier

I am creating a new record via XMLRPC.

Specificaly, I want to populate the field team_id in crm.lead .

I would like to populate that field using sales_team.salesteam_website_sales (ie the external XML ID ) instead of the number 2 (ie the regular ID ).

Is that possible using XMLRPC create , if so, what shall I use?

Odoo 10 CE

Take a look at this method of ir.model.data :

@api.model
def _get_id(self, module, xml_id):
    """Returns the id of the ir.model.data record corresponding to a given module and xml_id (cached) or raise a ValueError if not found"""
    return self.xmlid_lookup("%s.%s" % (module, xml_id))[0]

It can be used to replace the functionality of self.env.ref .

Call it from XMLRPC (send the module name and the XML ID as parameters), and it will return the ID in database of the record with that XML ID. Store that ID in a variable and use this variable to populate team_id .

The XMLRPC code will vary depending on the programming language you're using (Pyhon, PHP, Ruby or Java).

EDIT

As @Naglis said, the method I suggested you is not going to work, as it's a private method. Use the public one, xmlid_to_res_id , to achieve what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM