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

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

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

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

【开发】Report_Webkit 报表制作方法





  • (1) 在系统用户(设置/用户/用户)列表界面和表单界面,可以打印用所所有的权限组及访问数据库表的权限请单(样式见附件)
    (2)采用Webkit引擎实现



  • (1)在“addons” 目录新建一个目录,命名为:“report_webkit_demo”
    (2)添加两个文件
            ----    init.py
            ----    openerp.py

    init.py (不添加内容)
    openerp.py (按odoo模块要求添加)

    {<br />&nbsp; &nbsp; &#039;name&#039;: &#039;webkit report demo&#039;,<br />&nbsp; &nbsp; &#039;version&#039;: &#039;1.1&#039;,<br />&nbsp; &nbsp; &#039;author&#039;: &#039;&#039;,<br />&nbsp; &nbsp; &#039;summary&#039;: &#039;webkit, report, demo&#039;,<br />&nbsp; &nbsp; &#039;description&#039;: &quot;&quot;&quot;<br />webkit report demo<br />==============================================================<br />&nbsp; &nbsp; &quot;&quot;&quot;,<br />&nbsp; &nbsp; &#039;website&#039;: &#039;&#039;,<br />&nbsp; &nbsp; &#039;images&#039;: &#91;],<br />&nbsp; &nbsp; &#039;depends&#039;: &#91;&#039;report_webkit&#039;],<br />&nbsp; &nbsp; &#039;category&#039;: &#039;&#039;,<br />&nbsp; &nbsp; &#039;sequence&#039;: 16,<br />&nbsp; &nbsp; &#039;demo&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;data&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;test&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;installable&#039;: True,<br />&nbsp; &nbsp; &#039;application&#039;: True,<br />&nbsp; &nbsp; &#039;auto_install&#039;: False,<br />&nbsp; &nbsp; &#039;qweb&#039;: &#91;],<br />}
    


    (3)以上为odoo模块所要求的最基础两个文件,建立完成后可,更新“模块列表”,然后进行安装,如无问题进入下一步。



  • 步骤1的基础上

    (1)在"report_webkit_demo"目录下建立子文件夹“report”
    (2)在“report”文件夹下建立始下代码文件:
    init.py :  空

    webkit_report_demo.mako 报表模板文件

    <br />&lt;!DOCTYPE html&gt;<br />&lt;html&gt;<br />&lt;head&gt;<br />&nbsp; &nbsp; &lt;style type=&quot;text_css&quot;&gt;${css}&lt;/style&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&nbsp; &nbsp; % for user in objects:<br />&nbsp; &nbsp; &lt;h1&gt;${user.name} Access Informations:&lt;/h1&gt; <br />	&nbsp; &nbsp; % for group in user.groups_id:<br />		&lt;h2&gt;Group Name:${group.name}&lt;/h2&gt;<br />		&nbsp; &nbsp; &lt;table border=&quot;1&quot; width=&quot;100%&quot;&gt;<br />			&nbsp; &nbsp; &lt;tr&gt;<br />				&nbsp; &nbsp; &lt;th width=&quot;40%&quot;&gt;Model&lt;/th&gt;<br />					&lt;th&gt;Read&lt;/th&gt;<br />					&lt;th&gt;write&lt;/th&gt;<br />					&lt;th&gt;Create&lt;/th&gt;<br />					&lt;th&gt;Delete&lt;/th&gt;<br />				&lt;/tr&gt;<br />		&nbsp; &nbsp; % for access in group.model_access:<br />			&nbsp; &nbsp; &lt;tr&gt;<br />			&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;${access.model_id.name}&lt;/td&gt;<br />					&lt;td&gt;${access.perm_read}&lt;/td&gt;<br />					&lt;td&gt;${access.perm_write}&lt;/td&gt;<br />					&lt;td&gt;${access.perm_create}&lt;/td&gt;<br />					&lt;td&gt;${access.perm_unlink}&lt;/td&gt;					<br />			&nbsp; &nbsp; &lt;/tr&gt;<br />			% endfor<br />			&lt;/table&gt;		<br />		% endfor		<br />&nbsp; &nbsp; % endfor<br /><br />&nbsp; &nbsp; &lt;p&gt;The administrator name is: ${admin_name}&lt;/p&gt;<br />&nbsp; &nbsp; &lt;p&gt;If this report does not contain headers, it is because you have a badly compiled wkhtmltopdf. Consider installing<br />&nbsp; &nbsp; &nbsp; &nbsp; the static version distributed on the official web site: &lt;a href=&quot;https://code.google.com/p/wkhtmltopdf/&quot;&gt;https://code.google.com/p/wkhtmltopdf/&lt;/a&gt;.&lt;/p&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br />
    



    webkit_report_demo.py :报表数据准备代码,非必须(本DEMO中只为说明如何使用,加入了个简单的例子)

    <br />from openerp.addons.report_webkit.webkit_report import webkit_report_extender<br />from openerp import SUPERUSER_ID<br /><br />@webkit_report_extender(&quot;report_webkit_demo.webkit_demo_report_users&quot;)<br />def extend_demo(pool, cr, uid, localcontext, context):<br />&nbsp; &nbsp; admin = pool.get(&quot;res.users&quot;).browse(cr, uid, SUPERUSER_ID, context)<br />&nbsp; &nbsp; localcontext.update({<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;admin_name&quot;: admin.name,<br />&nbsp; &nbsp; })<br />
    



    webkit_report_demo.xml  :在“用户”增加界面菜单,并关联报表模板

    <br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;report string=&quot;Report on users&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=&quot;webkit_demo_report_users&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model=&quot;res.users&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=&quot;webkit.res.users.report.xml&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file=&quot;report_webkit_demo/report/webkit_report_demo.mako&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_type=&quot;webkit&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &lt;/data&gt;<br />&lt;/openerp&gt;<br />
    






  • 在步骤2的基础上:
    (1)更新report_webkit_demo/report/init.py文件

    <br />import webkit_report_demo<br />
    


    (2)更新report_webkit_demo/init.py文件

    <br />import report<br />
    


    (3)更新report_webkit_demo/openerp.py文件  : 将 "report/webkit_report_demo.xml"文件加入,在模块安装或更新时,对该文件加载。

    {<br />&nbsp; &nbsp; &#039;name&#039;: &#039;webkit report demo&#039;,<br />&nbsp; &nbsp; &#039;version&#039;: &#039;1.1&#039;,<br />&nbsp; &nbsp; &#039;author&#039;: &#039;lihaihe@hotmail.com&#039;,<br />&nbsp; &nbsp; &#039;summary&#039;: &#039;webkit, report, demo&#039;,<br />&nbsp; &nbsp; &#039;description&#039;: &quot;&quot;&quot;<br />webkit report demo<br />==============================================================<br />&nbsp; &nbsp; &quot;&quot;&quot;,<br />&nbsp; &nbsp; &#039;website&#039;: &#039;&#039;,<br />&nbsp; &nbsp; &#039;images&#039;: &#91;],<br />&nbsp; &nbsp; &#039;depends&#039;: &#91;&#039;report_webkit&#039;],<br />&nbsp; &nbsp; &#039;category&#039;: &#039;&#039;,<br />&nbsp; &nbsp; &#039;sequence&#039;: 16,<br />&nbsp; &nbsp; &#039;demo&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;data&#039;: [<br />	&nbsp; &nbsp; &quot;report/webkit_report_demo.xml&quot;,<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;test&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;installable&#039;: True,<br />&nbsp; &nbsp; &#039;application&#039;: True,<br />&nbsp; &nbsp; &#039;auto_install&#039;: False,<br />&nbsp; &nbsp; &#039;qweb&#039;: &#91;],<br />}
    


    (4)进入设置>本地模块,找到report_webkit_demo模块,对其更新。
    (5)进入设置>用户>用户,选择用户进行打印,或进入表单界面进行打印。



  • (1)DEMO模块下载地址:请在附件下载测试
    (2)在Odoo 8.0版本和master版本下测试通过
    (3)关于mko文件中加入中文件报错的解决办法:<br / http://shine-it.net/index.php/topic,16668.msg29220.html#msg29220 br />(3)代码参考report_webkit模块的demo代码


    全文完!欢迎讨论。



  • 目前Report_webkit,本身没有生产条码的功能,查了一些资料,如果想打印条码有以下几种方法:
    (1)采用条码字体的方式
    (2)在数据库里建一个函数类型的二进制字段,将生成的条码图像存进去,然后以图片的方式在MaKO文件调用
    (3)在做报表打印的数据准备时,生成条码图片,然后在MaKO文件调用