2012-11-30 4 views
3

여러 개체를보고 엔진에 전달하는 방법은 무엇입니까?OpenERP 보고서에 여러 개체 추가

송장에 표시 할 다른 응용 프로그램의 데이터를 첨부해야하는 곳에서 사용자 지정 송장 리포트를 만들려고합니다. 웹 서비스를 사용하여 OpenERP 서버로 데이터를 가져올 수 있지만이를보고 엔진에 전달하는 방법은 무엇입니까? 그것은 나를 하나는 전체 개체를 전달 얼마나하지만 보고서에 사용자 정의 변수를 전달할 수 있습니다으로 는 아마도

set_context or (self.localcontext.update()) 

방법은 여기에 도움이 될 것입니다.

다른 응용 프로그램에서 가져 오는 내용은 본질적으로 현재 파트너와 관련된 100 개의 레코드가있는 대규모 테이블입니다. OpenERP 데이터베이스에 저장할 필요가 없으며 인보이스 생성 중에 표시 할 수 있습니다.

편집 :

내가 파서

class test_invoice(report_sxw.rml_parse): 
def __init__(self, cr, uid, name, context): 
    super(test_invoice, self).__init__(cr, uid, name, context=context) 
    self.localcontext.update({ 
     'time': time, 
     'test_var': 'Worked!', 
     'get_list': self._get_list, 
    }) 


def _get_list(self): 
    result = [] 
    ress = {'first': '1', 
     'second': '2', 
     } 
    result.append(ress) 
    return result 

에와 RML 파일

...start of rml file 
    <section> 
     <para> 
      [[ repeatIn(get_list(), 'g')]] 
      [[ g.first ]] 
     </para> 
    </section> 

    </story> 
</document> 

에있는 개체를 테스트하지만이 유니 코드로 강요 오류 "가 발생하려면 : 필요 문자열을 또는 버퍼, 튜플을 찾았습니다 ". rml에 커스텀리스트를 어떻게 표시 할 수 있습니까?

감사합니다.

답변

2

당신은 OpenERP (물론, 여러분이 OpenERP를 사용하여 실행하는 python)까지 객체 전체를 전달할 수 있습니다. 그렇지 않으면 개체를 '프록시'해야합니다. 외부 db에서 데이터를 가져 오는 데 SQLAlchemy를 사용하면 몇 가지 해결책이 될 수 있습니다. 당신이 CSV 데이터를 관리하는 경우

[...somewhere into your parser...] 
self.localcontext.update({'external_rows': session.query(MyObject).filter_by(foo='baz')}) 

또는 : 당신은 그런 일에 손 수 _get_myrows_from_csv는 예를 들어 사전의 목록을 반환

self.localcontext.updarte({'external_rows': self._get_myrows_from_csv()}) 

.

+0

답장을 보내 주셔서 감사합니다. rml에서 단일 변수를 가져올 수 있지만 여전히 목록에 문제가 있습니다. OP에서 수정 사항을 확인 하시겠습니까? – Moin

2

RML 파일에서 결과 (사전)를 사용하는 것 외에는 모든 것을 올바르게하고 있습니다. 문제는 당신이 객체의 속성과 사전 값에 액세스하려고하는 것입니다

[[ g['first'] ]] 

대신

[[ g.first ]] 

보십시오. RML 파일에서

1

:

<story> 
    <section> 
     <para>[[ repeatIn(products(), 'p') ]]</para> 
     <blockTable colWidths="100.0,100.0" > 
      <tr> 
       <td> 
        <para>[[p.name]]</para> 
       </td> 

       <td> 
        <para>[[p.list_price]]</para> 
       </td> 
      </tr> 
     </blockTable > 
    </section> 
</story> 

보고 파서에서 :

class myreport(report_sxw.rml_parse): 
    def __init__(self, cr, uid, name, context): 
     super(myreport, self).__init__(cr, uid, name, context=context) 

     self.cr = cr 
     self.uid = uid 
     self.context = context 

     self.localcontext.update({ 
      'products': self._get_products 
      }) 

    def _get_products(self, ids=[85, 81, 89]): 
     return [p for p in self.pool.get('product.product').browse(self.cr, self.uid, ids, self.context)] 

나는 유용 할 바랍니다.

관련 문제