Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

請教報表rml中的程式撰寫



  • 小弟想在輸出的報表內另外讀取其他Table以及程式運算的資料
    在研究過老肖的OpenERP 应用和开发基础中關於编写RML 文件的部分--其中並未說明如何加入程式運算
    後來看到[b]Joshua[/b]大的关于openerp里面的报表,其中說道--
    [b]在RML里嵌入python语句,这些python语句从数据库(或者对象)里取数据生成报表。这个处理和html里嵌入java语句做jsp类似[/b]

    但我直接於加入python程式碼於rml檔中,並無作用
    [[
    cr.execute("select id from account_invoice where id=44")
            resM = cr.fetchall()
              if resM:
                  for rowM in resM:
                      x_model_code=str(rowM[0])
                      print x_model_code
    ]]

    想請問是我的標籤錯誤還是要在另處作程式運算,如果是不是在本rml檔中而是其他檔案那要如何傳入(rml中的語法似乎不同於python)
    感恩賜教


  • 管理员

    在RML parser中注册你在报表中要使用的函数或者方法,如下(其中myfunc就是定义好要在报表中使用的函数):

    class order(report_sxw.rml_parse):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp;  def __init__(self, cr, uid, name, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp;  super(order, self).__init__(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp;  self.localcontext.update({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &#039;time&#039;: time, &#039;myfunc&#039;: myfunc<br />&nbsp; &nbsp; &nbsp; &nbsp;  })<br />
    



  • [quote author=digitalsatori link=topic=2849.msg9587#msg9587 date=1332492172]
    在RML parser中注册你在报表中要使用的函数或者方法,如下(其中myfunc就是定义好要在报表中使用的函数):

    class order(report_sxw.rml_parse):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp;  def __init__(self, cr, uid, name, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp;  super(order, self).__init__(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp;  self.localcontext.update({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &#039;time&#039;: time, &#039;myfunc&#039;: myfunc<br />&nbsp; &nbsp; &nbsp; &nbsp;  })<br />
    


    [/quote]

    小弟按照大大解說施作但出現Error--找不到自定義的function
    [b] (<type 'exceptions.NameError'>, NameError("global name 'getorigininv' is not defined",), <traceback object at 0x0701E710>)[/b]
    懇請賜教是何原因

    程式如下 RML parser
        def init(self, cr, uid, name, context):
            super(account_invoice, self).init(cr, uid, name, context=context)
            self.localcontext.update({
                'time': time, 'getorigininv': getorigininv
            })

        def getorigininv(inv_name,inv_type,pro_id):
            sStr2=':'
            reorder_no=inv_name[inv_name.find(sStr2)+1:]
            if inv_type=='in_refund':
                cr.execute("""select id from account_invoice where origin="""+reorder_no)
                res = cr.fetchall()
                if res:
                    for row in res:
                        origin_inv_id=str(row[0])
                        cr.execute("""select price_unit,price_subtotal,quantity from account_invoice_line where product_id='"""+pro_id+"""' and invoice_id='"""+origin_inv_id+"""'""")
                        resP = cr.fetchall()
                        if resP:
                            for rowP in resP:
                                price_unit=strP(row[0])
                                price_subtotal=strP(row[1])
                                quantity=strP(row[2])

                return 'Origin_price_unit:'+price_unit

    RML檔呼叫
    [[getorigininv(o.name,o.type,lt.product_id)]]



  • <br /><br />&nbsp; &nbsp; &nbsp; &nbsp; self.localcontext.update({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;time&#039;: time, &#039;getorigininv&#039;: self.getorigininv<br />&nbsp; &nbsp; &nbsp; &nbsp; })<br /><br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; def getorigininv(self, inv_name,inv_type,pro_id):<br /><br />.....<br /><br />....<br />
    


  • [quote author=mrshelly link=topic=2849.msg9601#msg9601 date=1332740277]

    <br /><br />&nbsp; &nbsp; &nbsp; &nbsp; self.localcontext.update({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;time&#039;: time, &#039;getorigininv&#039;: self.getorigininv<br />&nbsp; &nbsp; &nbsp; &nbsp; })<br /><br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; def getorigininv(self, inv_name,inv_type,pro_id):<br /><br />.....<br /><br />....<br />
    


    [/quote]

    不好意思 想再請教在RML內檔呼叫該Function的方式是否也如同一般Python呼叫Function
    [b][[getorigininv(self,name,type,product_id)]][/b]

    因為用在Eclipse執行Debug模式 程式並無進入該Function執行?--表示根本沒有呼叫到該Function

    感恩賜教



  • <br />....<br />&lt;td&gt;[[ getorigininv(name, type, product_id)]]&lt;/td&gt;<br />....<br />
    


Log in to reply