2013-05-13 2 views
0

many2one field.but을 작성해야합니다. 함수 내 논리대로 데이터를 필터링해야합니다. OpenERP ver 7에서 이것을 구현하는 방법은 무엇입니까? res.users와 many2one 필드를 USER_ID 확인함수가있는 OpenERP many2one 필드

def _get_users(self, cr, uid, ids, field_name, arg, context=None): 
    res = {} 
    users_list=[] 
    officer_ids = self.search(cr, uid , 'bpl.officer', [('is_user', '=', True)]) 
    officer_obj = self.browse(cr, uid, officer_ids, context=context) 
    for record in officer_obj: 
     users_list.append(record.user_id.id) 
    user_obj = self.pool.get('res.users') 
    for data in self.browse(cr, uid, ids, context=context): 
     res[data.id] = users_list 
    return res 

_name = "bpl.officer" 
_description = "Officer registration details" 
_columns = { 
    'bpl_company_id':fields.many2one('res.company', 'Company', help='Company'), 
    'bpl_estate_id':fields.many2one('bpl.estate.n.registration', 'Estate', help='Estate', domain="[('company_id', '=', bpl_company_id)]"), 
    'bpl_division_id':fields.many2one('bpl.division.n.registration', 'Division', help='Division', domain="[('estate_id','=',bpl_estate_id)]"), 
    'name': fields.char('Name', size=128, required=True), 
    'is_user': fields.boolean('Is User', help="Is System user or not"), 
    'user_id': fields.function(_get_users, type="many2one",relation="res.users"), 

답변

5

첫째 : 직접 도메인을 추가 할 수있는 방법이 없기 때문에

, 나는 당신이 같은 맥락의 기초에 res.users의 검색 메소드를 오버라이드 (override) 할 필요가 있다고 생각 wrong.user_id 그 자체는 기능적인 필드이며, 어떤 마법을 사용하고있다 (나는 이해하지 못한다). many2one 필드로 변경하십시오.

일부 레코드를 필터링하려면 xml 파일에 user_id 필드를 추가 할 도메인 필터를 추가하면됩니다. 예를 들어 <field name="user_id" domain="[('is_user', '=', True)]"/> 인 경우 is_user는 res_partner 테이블의 필드입니다. 그 외에도 fields_view_get 함수를 사용하고 거기에서 도메인을 추가 할 수 있습니다.

+1

그것은 있어야합니다 is_user가 res.users 객체에 정의 된 경우 유용합니다. 소스별로, 그것은 bpl.officer 객체로 정의됩니다. –

+0

예, AnomA. 다른 클래스의 필드와 비교하는 레코드를 필터링해야합니다. 그럼 어떻게 구현해야합니까? –

+0

http://stackoverflow.com/questions/6569828/how-to-create-a-dynamic-view-on-openerp이 게시물에 대한 답변을 확인하십시오. – OmaL

1

첫째 :

내가는 읽기 전용 필드로 list.just 부하를주지 아래 code.but로했습니다.

res.users 개체의 해당 컨텍스트를 기반으로 컨텍스트를 추가하고 검색 방법을 재정의하고 논리에 따라 레코드를 반환 할 수 있습니다. 사용자가 만든 모든 기능 필드의

def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): 
     if context is None: 
      context = {} 
     users_list = [] 
     if context.get('test') == 'test': 
      officer_ids = OFFICE_OBJ.search(cr, uid , [('is_user', '=', True)]) 
      officer_obj = OFFICE_OBJ.browse(cr, uid, officer_ids, context=context) 
      for record in officer_obj: 
       users_list.append(record.user_id.id) 
       return users_list 
     return super(res_users, self).search(cr, uid, args, offset, limit, 
       order, context=context, count=count) 
+0

이 하나 더 좋은 해결책이 – senthilnathang

+0

안녕하세요 @Priyesh Solanki 제발 many2one 필드 또는 다른 방법으로 회사의 연락 담당자를 얻을 수 내게 사용자 정의 양식을 기쁘게 도와달라고 도와주세요 –

관련 문제