跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. 請教報表rml中的程式撰寫

請教報表rml中的程式撰寫

已定时 已固定 已锁定 已移动 Odoo 新手求助
7 帖子 3 发布者 4.2k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • K 离线
    K 离线
    kk071700
    写于 最后由 编辑
    #1

    小弟想在輸出的報表內另外讀取其他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)
    感恩賜教

    1 条回复 最后回复
    0
    • digitalsatoriD 离线
      digitalsatoriD 离线
      digitalsatori 管理员
      写于 最后由 编辑
      #2

      在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 />
      

      【上海先安科技】(tony AT openerp.cn)

      1 条回复 最后回复
      0
      • K 离线
        K 离线
        kk071700
        写于 最后由 编辑
        #3

        [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)]]

        1 条回复 最后回复
        0
        • mrshellyM 离线
          mrshellyM 离线
          mrshelly
          写于 最后由 编辑
          #4
          <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 />
          
          1 条回复 最后回复
          0
          • K 离线
            K 离线
            kk071700
            写于 最后由 编辑
            #5

            [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

            感恩賜教

            1 条回复 最后回复
            0
            • mrshellyM 离线
              mrshellyM 离线
              mrshelly
              写于 最后由 编辑
              #6
              <br />....<br />&lt;td&gt;[[ getorigininv(name, type, product_id)]]&lt;/td&gt;<br />....<br />
              

              1 条回复 最后回复
              0

              • 登录

              • 没有帐号? 注册

              • 登录或注册以进行搜索。
              • 第一个帖子
                最后一个帖子
              0
              • 版块
              • 标签
              • 热门
              • 用户
              • 群组