Odoo中文网|Odoo实施培训

 找回密码
 立即注册
搜索
热搜: Odoo OpenERP 实施
查看: 6714|回复: 0
打印 上一主题 下一主题

odoo qweb report调用python代码

[复制链接]

1

主题

1

帖子

7

积分

新手上路

Rank: 1

积分
7
跳转到指定楼层
楼主
发表于 2015-9-12 18:01:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
          
  
       1.添加一个python文件
在它的__init__.py中注册

2.添加一个与template对应的类



Python代码  

  • class report_test(osv.AbstractModel):  
  •     _name = 'report.my_module.report_test'  
  •     _inherit = 'report.abstract_report'  
  •     _template = 'my_module.report_test'  



这里module是my_module
report template是report_test

3.添加一个用于template调用的类

Python代码  

  • class test_wrapped():  
  •   
  •     def __init__(self, cr, uid, name, context=None):  
  •         if context is None:  
  •             context = {}  
  •         super(test_wrapped, self).__init__(cr, uid, name, context=context)  
  •         self.localcontext.update( {  
  •             'time': time,  
  •         })  
  •   
  •     def set_context(self, objects, data, ids, report_type=None):  
  •         return super(test_wrapped, self).set_context(objects, data, ids, report_type=report_type)  
  •   
  •     def foo(self):  
  •         return True  

这里的foo就是用来调用的方法了。

3.把这个类告诉template
Python代码  

  • class report_test(osv.AbstractModel):  
  •     _name = 'report.my_module.report_test'  
  •     _inherit = 'report.abstract_report'  
  •     _template = 'my_module.report_test'  
  •     _wrapped_report_class = test_wrapped  


4.现在就可以在qweb里调用了
Xml代码  

  • <t t-if="foo()">  
  • foo called  
  • </t>  


5.如果你想调用rml_parse中的方法,如formatLang,可以让test_wrapped继承rml_parse

Python代码  

  • class test_wrapped(report_sxw.rml_parse):  
  •   
  •     def __init__(self, cr, uid, name, context=None):  
  •         if context is None:  
  •             context = {}  
  •         super(test_wrapped, self).__init__(cr, uid, name, context=context)  
  •         self.localcontext.update( {  
  •             'time': time,  
  •         })  
  •   
  •     def set_context(self, objects, data, ids, report_type=None):  
  •         return super(test_wrapped, self).set_context(objects, data, ids, report_type=report_type)  
  •   
  •     def foo(self):  
  •         return True  



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|技术支持|开发手册|Odoo中文网-远鼎旗下odoo培训网站 ( 苏ICP备15039516号 )

GMT+8, 2024-4-19 21:55 , Processed in 0.013339 second(s), 15 queries , Xcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表