2016-11-11 1 views
0

클릭하면 트리 뷰 레코드를 클릭하여 formview를 열고 싶습니다. Formview가 열리면 동적으로 채워 져야하는 두 개의 one2many 필드가 있습니다. (제품 목록이 있고 제품을 클릭하면이 제품에 대해 재고 이동이 몇 개 있었는지 검색하려고합니다)Openerp v7 API 함수 필드 'one2many'유형

def get_last_sales(self, cr, uid, ids, context=None): 
    customer_loc_id = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'customer')]) 
    result = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', ids), ('location_dest_id', '=', customer_loc_id)]) 
    print result 
    #raise Exception 
    return result 

def get_last_productions(self, cr, uid, ids, context=None, args=None, kwargs=None): 
    production_loc_id = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'production')]) 
    result = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', ids), ('location_dest_id', '=', production_loc_id)]) 
    return result 

내가 원하는 것은 fields.function 필드와 비슷한 기능입니다. 이 작업을해야하지만 그렇지 않습니다 :

'last_sales':fields.function(_get_last_sales, type='one2many', relation='stock.move', readonly=True, store=store_triggers)

Server Traceback (most recent call last): File "/home/george/odoo/mattia_v7/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/home/george/odoo/mattia_v7/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/george/odoo/mattia_v7/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/home/george/odoo/mattia_v7/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/george/odoo/mattia_v7/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/home/george/odoo/mattia_v7/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/george/odoo/mattia_v7/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/home/george/odoo/mattia_v7/openerp/osv/orm.py", line 3718, in read result = self._read_flat(cr, user, select, fields, context, load) File "/home/george/odoo/mattia_v7/openerp/osv/orm.py", line 3841, in _read_flat res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res) File "/home/george/odoo/mattia_v7/openerp/osv/fields.py", line 1152, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) File "/home/george/odoo/mattia_v7/openerp/addons/product/product.py", line 461, in _product_lst_price res[product.id] = product.list_price File "/home/george/odoo/mattia_v7/openerp/osv/orm.py", line 503, in __getattr__ return self[name] File "/home/george/odoo/mattia_v7/openerp/osv/orm.py", line 469, in __getitem__ elif field_column._type in ('one2many', 'many2many') and len(result_line[field_name]): TypeError: object of type 'bool' has no len()

내가이 지원하지 않는 것 같습니다 것을 https://www.odoo.com/forum/help-1/question/can-i-store-field-function-with-the-type-one2many-356

에 볼 수 있습니다. 답변이 맞습니까? 이것에 대한 해결 방법이 있습니까? 다음 코드

+0

* _get_last_sales * 메소드로 질문을 업데이트하십시오. –

+0

@Odedra 내 질문 업데이트 –

답변

1

예, 저장 x2many 기능이나 계산 필드를 전혀 이해되지 않는다. 왜? 두 가지 유형 모두 필드 설정에서 수행 할 수없는 특별한 설정이 필요합니다. one2Many에서는 다른 모델에 관련된 외래 키가 필요합니다. many2many에서는 두 모델 키의 테이블을 정의해야합니다.

odoo에 대한 나의 경험에 따르면, 저장되지 않은 many2many 함수 필드를 사용합니다 (함수는 일반적인 사전에있는 ID 목록을 반환해야 함).

또한 @Odedra가 답변에서 언급 한 것처럼 함수가 올바르지 않습니다.

1

시도 :

def get_last_sales(self, cr, uid, ids, context=None): 

    customer_loc_id = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'customer')]) 
    result = {} 

    if customer_loc_id: 

     for record in self.browse(cr, uid, ids): 

      result[record.id] = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', record.id), ('location_dest_id', '=', customer_loc_id[0])]) 

    return result 

def get_last_productions(self, cr, uid, ids, context=None, args=None, kwargs=None): 

    production_loc_id = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'production')]) 
    result = {} 

    if production_loc_id: 

     for record in self.browse(cr, uid, ids): 

      result[record.id] = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', record.id), ('location_dest_id', '=', production_loc_id[0])]) 

    return result 

'last_sales':fields.function(_get_last_sales, type='one2many', relation='stock.move', readonly=True, string='Last Sales') 
+0

좀 더 자세히 설명해주십시오.이 코드는 무엇을하고 있습니까? 내가 왜 이걸 써야 할까? –

+0

이 코드는 문제를 해결할 것입니다. 당신의 코드에는 많은 문제가 있습니다. 예를 들어 특정 레코드 ID에 값을 전달하지 않았습니다. 우리가 * = * 연산자를 사용할 때, 적절한 값을 설정할 필요가 있습니다. 귀하의 경우 목록을 통과했습니다. * (customer_loc_id) * 및 * (production_loc_id) * –

+0

시간과 응답에 감사드립니다. @Odedra. 하지만 내 주요 문제는 이러한 방법에 있지 않습니다. 내 주요 문제는 내 레코드의 폼보기를 열 때 메서드를 호출하는 방법입니다. 이미 삭제 된 메소드를 무시하십시오. 방금 호출 한 메소드를 호출했는지 확인하기 위해 방금 삽입했습니다. –