1

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 (i.e. the external XML ID) instead of the number 2 (i.e. the regular ID).

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

Odoo 10 CE

forvas
  • 9,801
  • 7
  • 62
  • 158
M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

2

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.

forvas
  • 9,801
  • 7
  • 62
  • 158
  • 1
    Unfortunately, private model methods (starting with an underscore) cannot be called via XML/JSON RPC. [[1](https://github.com/odoo/odoo/blob/815c2a324dde5dc55c15c46b36c2ec45f653e22c/odoo/models.py#L104-L107)], [[2](https://github.com/odoo/odoo/blob/815c2a324dde5dc55c15c46b36c2ec45f653e22c/odoo/service/model.py#L163)]. Suggest to use [`xmlid_to_res_id`](https://git.io/vxmVD) on `ir.model.data` model. – Naglis Mar 16 '18 at 15:42
  • 1
    I didn't realized that, so @Naglis provided the right answer. Thanks for the info, I'll edit the answer. – forvas Mar 20 '18 at 09:14