請教報表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):                                                                                                                                    <br />    def __init__(self, cr, uid, name, context=None):<br />        super(order, self).__init__(cr, uid, name, context=context)<br />        self.localcontext.update({<br />            'time': time, 'myfunc': myfunc<br />        })<br />
 
- 
[quote author=digitalsatori link=topic=2849.msg9587#msg9587 date=1332492172] 
 在RML parser中注册你在报表中要使用的函数或者方法,如下(其中myfunc就是定义好要在报表中使用的函数):class order(report_sxw.rml_parse):                                                                                                                                    <br />    def __init__(self, cr, uid, name, context=None):<br />        super(order, self).__init__(cr, uid, name, context=context)<br />        self.localcontext.update({<br />            'time': time, 'myfunc': myfunc<br />        })<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 />        self.localcontext.update({<br />            'time': time, 'getorigininv': self.getorigininv<br />        })<br /><br />....<br />        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 />        self.localcontext.update({<br />            'time': time, 'getorigininv': self.getorigininv<br />        })<br /><br />....<br />        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
 感恩賜教

