我使用xmlrpc搜索postgres odoo数据库中的数据。
在表格中搜索时,res_partner一切都很好。
现在我想在res_partner_title中搜索,但它不会返回ID。
我的数据库内容:
myDatabase=# select * from res_partner_title;
id | create_uid | create_date | name | shortcut | write_uid | write_date
----+------------+----------------------------+-----------+----------+-----------+----------------------------
1 | 1 | 2017-12-29 09:26:11.139936 | Madam | Mrs. | 1 | 2017-12-29 09:26:11.139936
2 | 1 | 2017-12-29 09:26:11.139936 | Miss | Miss | 1 | 2017-12-29 09:26:11.139936
3 | 1 | 2017-12-29 09:26:11.139936 | Sir | Sr. | 1 | 2017-12-29 09:26:11.139936
4 | 1 | 2017-12-29 09:26:11.139936 | Mister | Mr. | 1 | 2017-12-29 09:26:11.139936
5 | 1 | 2017-12-29 09:26:11.139936 | Doctor | Dr. | 1 | 2017-12-29 09:26:11.139936
6 | 1 | 2017-12-29 09:26:11.139936 | Professor | Prof. | 1 | 2017-12-29 09:26:11.139936
(6 rows)
我的代码:
myData = myObject.search('res.partner.title', [('shortcut','=','Mr.')])
class MyClass:
def __init__(self, host, port, username, pwd, dbname, context, dbsuperpwd=None,
dbuser=None, dbpasswd=None):
self.sock_common = xmlrpclib.ServerProxy ("http://" + host + ":" + str(port) + "/xmlrpc/common")
self.uid = self.sock_common.login(dbname, username, pwd)
self.sock = xmlrpclib.ServerProxy("http://" + host + ":" + str(port) + "/xmlrpc/object")
self.dbname = dbname
self.pwd = pwd
self.dbsuperpwd = dbsuperpwd
self.context = context
def search(self, modelname, query, offset=0, limit=0, order=False,
context=None):
context = context or self.context
for i in range(MAX_RETRIES):
try:
return self.sock.execute(self.dbname, self.uid, self.pwd,
modelname, 'search', query, offset,
limit, order, context)
except socket.error:
pass
无论过滤器是什么,它总是返回1。
我怎样才能得到3(在我的例子中)?
编辑(添加评论询问数据)
context = {' lang':' es_ES'}
它返回1或0
我刚刚发现,它在odoo9中有效,在odoo10中失败
答案 0 :(得分:1)
我猜问题可能就是语言。您正在context
es_ES
发送并使用英语查找缩略图,因此现在尝试使用[('shortcut','ilike','%Sr.%')]
替换您当前的搜索域。
看看ir_translation
表:
id | lang | src | name | type | module | state | comments | value | res_id
------+-------+--------+----------------------------+-------+--------+------------+----------+-------+--------
6483 | es_ES | Mister | res.partner.title,name | model | base | translated | | Señor | 3
6559 | es_ES | Mr. | res.partner.title,shortcut | model | base | translated | | Sr. | 3