2014-04-24 8 views
3

이것은 매우 간단하지만 대답하기 어려운 질문입니다. "소수"사람들 만이 문제를 해결한다고 생각하기 때문입니다.OpenERP에서 현지 언어로 제품 이름을 찾으십니까?

import xmlrpclib 

username = 'my_openerp_user' 
pwd = 'my_password' 
dbname = 'my_openerp_database' 

sock = xmlrpclib.ServerProxy('http://localhost:8063/xmlrpc/common') 
uid = sock.login(dbname, username, pwd) 
sock = xmlrpclib.ServerProxy('http://localhost:8063/xmlrpc/object') 

args = [('name', 'ilike', 'my_product')] 
ids = sock.execute(dbname, uid, pwd, 'product.product', 'search', args) 

print ids 

그것은 이름이 'my_product'와 OpenERP 데이터베이스에있는 모든 제품을 찾을해야하지만, 그렇지 않습니다 :

는 파이썬이 간단한 스크립트가 있습니다. 그리고 나는 이유를 안다 :

나는 영어가 말한 나라가 아니기 때문에 OpenERP에 하나의 언어가 설치되어 있고 xmlrpc의 'search'는 'my_product'라는 이름의 제품을 찾고 있지만 영어로만되어있다. . 문제는 분명히 번역 된 이름을 저장할 필드가 없다는 것입니다 ... 그것은 역시 '이름'인 것처럼 보입니다! 제 언어로 이름을 지정하면 제품을 찾을 수 없습니다.

세계 누구나 ​​같은 문제가 있었습니까? 나는 언어를 지정할 수 있습니다

product_names = sock.execute(dbname, uid, pwd, 'product.product', 'read', ids, ['name'], {'lang': 'es_ES'}) 

이 방법을 그리고 그것은 작동합니다 내가 할 '읽기'대신 일을하면 '검색'

편집

좋아, 나는 실마리가! 하지만 '검색'을 통해 동일한 작업을 수행 할 수는 없습니다. 오류가 발생합니다. 누구나 방법을 알고 ???

NEW EDIT

context = {'lang': 'es_ES'} 

args = [('name', 'ilike', 'my_product')] # consulta 

ids = sock.execute(dbname, uid, pwd, 'product.product', 'search', args, context) 

답변

5

난 당신이 contextlang를 전달하면 작동한다 거의 확신합니다. 예 : context = {'lang': u'pl_PL'}

작동하지 않는 경우 name_search 메소드를 덮어 써야합니다.

+0

'읽기'와 작동하지만 '검색'이 작동합니까? – forvas

+0

그렇지 않습니까? 그것은 본다. expression.parse 메소드를 살펴 본다. (메소드의 끝에있는 else 블록에서). –

+0

죄송합니다. 조금 잃어 버렸습니다. 어디에서 표현식을 찾아야합니까? 파스? – forvas

1

검색 방법은 다음과 같이이다 : openerp에서

ids = sock.execute(dbname, uid, pwd, 'product.product', 'search', args, 0, 0, False, context) 
0

/OSV/표현 :

search(cr, uid, args, offset=0, limit=None, order=None, context=None, count=False) 

당신은 또한 인수와 컨텍스트 사이의 매개 변수를 보낼 수있는 컨텍스트를 보내려면. py 검색어가 ir_translation의 번역이 존재하지 않는 경우에만 원래의 이름을 영어로 번역하여 처음으로 번역을 검색하도록 수정되었습니다. OpenERP Server 6.0.4

query1 = '(SELECT res_id'   \ 
     ' FROM ir_translation' \ 
     ' WHERE name = %s'  \ 
     '  AND lang = %s'  \ 
     '  AND type = %s' 
instr = ' %s' 
#Covering in,not in operators with operands (%s,%s) ,etc. 
if operator in ['in','not in']: 
    instr = ','.join(['%s'] * len(right)) 
    query1 += '  AND value ' + operator + ' ' +" (" + instr + ")" + ')' 
else: 
    query1 += '  AND value ' + operator + instr + ')' 
query1 +=' UNION ('    \ 
     ' SELECT id'    \ 
     ' FROM "' + working_table._table + '"' + ' as wt ' \ 
     ' WHERE "'+ left + '" ' + operator + instr + \ 
     ' AND NOT EXISTS ( ' \ 
     '  SELECT res_id FROM ir_translation ' \ 
     '  WHERE wt.id = res_id ' \ 
     '  AND name = %s'  \ 
     '  AND lang = %s'  \ 
     '  AND type = %s)' + ")" 


query2 = [working_table._name + ',' + left, 
      context.get('lang', False) or 'en_US', 
      'model', 
      right, 
      right, 
      working_table._name + ',' + left, 
      context.get('lang', False) or 'en_US', 
      'model' 
      ]