Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6408 Lượt xem

Hello, I need help to understand what has happened in Odoo v15 regarding the 'get_object_reference' method call is now called '_xmlid_lookup'


modifying my migration compiler when I use that method I can't call '_xmlid_lookup' because it is private


Is there another way to get to use the equivalent of self.env.ref('') but for XMLRPC?


In Odoo V13 and Odoo V14 I used:

self.ServerProxyObjects.execute_kw('db', '4', '12345','ir.model.data', 'get_object_reference', ['base.USD'])


In Odoo v15 would be similar:

self.ServerProxyObjects.execute_kw('db', '4', '12345','ir.model.data', '_xmlid_lookup', ['base.USD'])


But _xmlid_lookup is private, result in console:

xmlrpc.client.Fault:xmlrpc.client.Fault: Fault 4: 'Private methods (such as _xmlid_to_res_id) cannot be called remotely


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I found the solution, reviewing the odoo source code I could see that the check_object_reference method does the same thing by calling the _xmlid_lookup method in v15 and in v13 and v14 get_object_reference, so this method would only be called and returns what is desired for all those versions, I will close my question since I found the solution.

Ảnh đại diện
Huỷ bỏ

Worked for me! thanks a lot.

Câu trả lời hay nhất

Hello bro, I needed to do the same thing. Although I'm getting a strange error. When I give two args it says me "3 were given" when I add only one it says "it needs two but 1 were given." how to solve this?


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Hello bro,
in v13 to reference a record stored in the db in odoo via XMLRPC, internally odoo has this method

odoo>addons>base>models>ir_model.py line:1728 - 1744

@api.model
def get_object_reference(self, module, xml_id):
"""Returns (model, res_id) corresponding to a given module and xml_id (cached) or raise ValueError if not found"""
return self.xmlid_lookup("%s.%s" % (module, xml_id))[1:3]

which one can call internally via a module like this:

self.env['ir.model.data'].get_object_reference('base_setup', 'action_general_configuration')

with XMLRPC I can call it like this by calling the method that wraps the other called method (check_object_reference) and sending this data

from xmlrpc import client as xmlrpclib
xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format('url')).execute_kw(db, uid, password,
'ir.model.data', 'check_object_reference',
['base', 'user_admin']
)
note: if you want to search for a xml record like 'base.user_admin' you have to send it separately --> 'base', 'user_admin'

which would give you an output in an array with a dictionary of the id number and the model
example: [(1, 'res.partner')] - something like this

I hope my explanation has helped you, if you still have problems tell me the source code maybe it will solve it

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
3841
1
thg 4 16
4765
3
thg 7 25
2781
1
thg 10 24
2017
1
thg 4 24
2044