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

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

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

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

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

基于Lodop的报表打印模块



  • 前段时间写了个小模块,来解决OE中报表打印不方便的问题。
    借鉴了 @buke 兄的 openerp-web-pdf-preview-print 模块的部分代码。

    介绍:
    Lodop是一款优秀的国产打印控件(activeX): [检测到链接无效,已移除]
    ActiveX只支持windows,所以本控件不适用linux,mac osx.

    模块使用mako标签,html的模版。

    我只贴代码,不加附件,这样各位会体会更深。

    模块结构:
    [attach=1]


    openerp.py

    <br />{<br />&nbsp; &nbsp; &quot;name&quot;: &quot;Lodop控件报表&quot;,<br />&nbsp; &nbsp; &quot;category&quot;: &quot;web&quot;,<br />&nbsp; &nbsp; &quot;description&quot;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; Lodop控件模块, 针对于报表。<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;,<br />&nbsp; &nbsp; &quot;version&quot;: &quot;6.0.5.6&quot;,<br />&nbsp; &nbsp; &quot;depends&quot;: &#91;],<br />&nbsp; &nbsp; &quot;js&quot;: [&quot;static/lib/Lodop6.145/*.js&quot;, &quot;static/js/*.js&quot;],<br />&nbsp; &nbsp; &#039;active&#039;:True,<br />&nbsp; &nbsp; &#039;installable&#039;: True,<br />&nbsp; &nbsp; &#039;active&#039;: False,<br />&nbsp; &nbsp; &#039;application&#039;:False,<br />}<br /><br />
    




    服务端的controller(没啥一样的,继续借鉴@buke):

    <br /># -*- coding: utf-8 -*-<br /><br /><br />import openerp.addons.web.http as openerpweb<br />from openerp.addons.web.controllers.main import View<br /><br />import urllib2<br />import simplejson<br />import base64<br />import time<br />import zlib<br />import cPickle<br />import hashlib<br /><br /><br />class LodopReport(View):<br />&nbsp; &nbsp; _cp_path = &quot;/web/lodop/report&quot;<br />&nbsp; &nbsp; POLLING_DELAY = 0.25<br /><br />&nbsp; &nbsp; @openerpweb.jsonrequest<br />&nbsp; &nbsp; def index(self, req, action):<br />&nbsp; &nbsp; &nbsp; &nbsp; action = simplejson.loads(action)<br />&nbsp; &nbsp; &nbsp; &nbsp; report_srv = req.session.proxy(&quot;report&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; context = dict(req.context)<br />&nbsp; &nbsp; &nbsp; &nbsp; context.update(action[&quot;context&quot;])<br />&nbsp; &nbsp; &nbsp; &nbsp; report_data = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; report_ids = context[&quot;active_ids&quot;]<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#039;report_type&#039; in action:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_data&#91;&#039;report_type&#039;] = action&#91;&#039;report_type&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#039;datas&#039; in action:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &#039;ids&#039; in action&#91;&#039;datas&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_ids = action&#91;&#039;datas&#039;].pop(&#039;ids&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_data.update(action&#91;&#039;datas&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; report_id = report_srv.report(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.session._db, req.session._uid, req.session._password,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action[&quot;report_name&quot;], report_ids,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_data, context)<br />&nbsp; &nbsp; &nbsp; &nbsp; report_struct = None<br />&nbsp; &nbsp; &nbsp; &nbsp; while True:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_struct = report_srv.report_get(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.session._db, req.session._uid, req.session._password, report_id)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if report_struct[&quot;state&quot;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(self.POLLING_DELAY)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; report = base64.b64decode(report_struct&#91;&#039;result&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; return dict(report = report)<br /><br />
    




    主要部分是js部分:

    <br /><br />openerp.fg_lodop = function(instance) {<br /><br />&nbsp; &nbsp; instance.web.ActionManager = instance.web.ActionManager.extend({<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; init: function (parent, action) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this._super(parent);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //activex的标签放在页面里。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var obj_string = &#039;&lt;object style=&quot;width:0px;height:0px;&quot; id=&quot;LODOP_OB&quot; classid=&quot;clsid:2105C259-1E0C-4534-8141-A753534CB4CA&quot; width=0 height=0&gt;&lt;embed id=&quot;LODOP_EM&quot; type=&quot;application/x-print-lodop&quot; width=0 height=0 pluginspage=&quot;/fg_lodop/static/lib/lodop6.145/install_lodop32.exe&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(obj_string).appendTo(&quot;body&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ir_actions_report_xml: function(action, options) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instance.web.blockUI();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return instance.web.pyeval.eval_domains_and_contexts({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contexts: [action.context],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; domains: &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).then(function(res) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action = _.clone(action);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action.context = res.context;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var os = navigator.platform || &quot;Unknown OS&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linux = os.indexOf(&quot;Linux&quot;) &gt; -1;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mac = os.indexOf(&quot;Mac&quot;) &gt; -1;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rpc(&quot;/web/lodop/report&quot;, {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action: JSON.stringify(action)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).done(function(result) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(result.error){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instance.web.unblockUI();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.dialog_stop();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instance.web.unblockUI();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.dialog_stop();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(linux || mac) { <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //不支持linux, mac, 这点没考虑过。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_window=window.open(&#039;&#039;,&#039;&#039;,&#039;width=600,height=500&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_window.document.write(result.report);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_window.focus();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //do magic.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 等会解释这个由来。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; format_obj = action.attachment.split(&#039;,&#039;);<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP=getLodop(document.getElementById(&#039;LODOP&#039;),document.getElementById(&#039;LODOP_EM&#039;));&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.SET_LICENSES(&quot;&quot;,&quot;xxxxxx&quot;,&quot;&quot;,&quot;&quot;);&nbsp; //不设置授权码照样可以打印。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.PRINT_INIT(&quot;FG ERP Order&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.SET_PRINT_PAGESIZE(1, 2300, 1390, &#039;fg_lodop_print_job&#039;); //公司用的各种单据的打印纸都是统一规格,所以写死了。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tables = $.parseHTML(result.report);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.each( tables, function( i, el ) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(el.nodeName == &quot;TABLE&quot;){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.ADD_PRINT_TABLE(format_obj[0],format_obj[1],format_obj[2], format_obj[3], el.outerHTML);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.NEWPAGE();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LODOP.PREVIEW();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br /><br /><br />};<br /><br /><br /><br />
    




    安装后,本模块将会替代系统默认的报表动作。

    使用方法:

    <br /><br />&lt;report auto=&quot;False&quot; id=&quot;report_fg_sale_cust_order_html&quot; model=&quot;fg_sale.cust.order&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=&quot;fg_sale.cust.order.html&quot; rml=&quot;fg_sale/report/cust_order.html&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string=&quot;定制单&quot; report_type=&quot;mako2html&quot; attachment=&quot;0mm,0mm,220mm,98mm&quot;/&gt;<br /><br />
    



    因为需要确定打印的范围,所以借用了attachment这个属性----实在是不想修改系统的rng文件了。
    * 这就是刚才代码 “format_obj = action.attachment.split(',');” 这一行的原因。


    mako的html模版大概是这样的:


    <br /># -*- coding: utf-8 -*-<br />&nbsp; &nbsp; 		% for o in objects:<br />&nbsp; &nbsp; 		&nbsp; &nbsp; % if o.state == &#039;review&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;table border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; bordercolor=&quot;#000000&quot; style=&quot;font-size:14px;width:850px;&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;thead&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;8&quot; align=&quot;center&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span style=&quot;font-size:18px;font-weight:bold;&quot;&gt;定制清单&nbsp; &lt;/span&gt; ${ o.name }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot;&nbsp; height=&quot;18&quot;&gt;客户名称: <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ${ o.partner_id.name }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&nbsp; height=&quot;18&quot;&gt;要求到货日期: ${ o.date_arrival_req or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;4&quot; height=&quot;18&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 交货日期: ${ o.date_delivery or &#039;&#039; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % if o.contact or o.phone or o.delivery_addr:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot;&gt;联系人: ${ o.contact or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;联系电话: ${ o.phone or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;交货地址: ${ o.delivery_addr or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % endif<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot;&gt;已付金额: ${ o.amount_paid or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;付款方式: ${ o.amount_paid_method or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;发票: <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % if o.invoice_type == &#039;common&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 普通发票<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % elif o.invoice_type == &#039;va&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 增值发票<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 暂不开票<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % endif<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot;&gt;定制版面:&nbsp; ${ o.client }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;运费承担方: ${ o.delivery_fee or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;3&quot;&gt;送货方式: ${ o.delivery_method or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr height=&quot;18&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 	&nbsp; &nbsp;  &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;品名&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 	&nbsp; &nbsp;  &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;数量(只)&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;开票价&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;版费&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;已发货&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;小计&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; align=&quot;center&quot;&gt;附注&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/thead&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tbody&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % for line in o.order_line:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; &gt;${ line.product_id.name }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;10%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot;&gt;${ line.product_uom_qty }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;10%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; &gt;${ line.unit_price }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;10%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot;&gt;${ line.cust_price }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;10%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot;&gt;${ line.delivered and &#039;是&#039; or &#039;否&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;10%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot;&gt;${ line.subtotal_amount }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td width=&quot;20%&quot; height=&quot;18&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot;&gt;${ line.note or &#039;&#039; }&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % endfor<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tbody&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tfoot&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;text-align:right;&quot; tdata=&quot;allSum&quot; format=&quot;#,##0.00&quot; tindex=&quot;6&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 共计: #<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;4&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; tdata=&quot;allSum&quot; format=&quot;UpperMoney&quot; tindex=&quot;6&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;2&quot; style=&quot;BORDER-COLLAPSE: collapse; BORDER:groove 1px;&quot; tdata=&quot;subSum&quot; format=&quot;#,##0.00&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 本页小计: #<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;2&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 开单人: ${ o&#91;&#039;user_id&#039;]&#91;&#039;name&#039;] } &amp;nbsp;&amp;nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 开单日期:${ o.date_order } <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;4&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 业务部确认: ${ o&#91;&#039;confirmer_id&#039;]&#91;&#039;name&#039;] }&amp;nbsp;&amp;nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 业务经办人:${ o.employee_id.name }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td colspan=&quot;1&quot; style=&quot;font-size:14px;height:18px;text-align:right;&quot;&gt;第&lt;span tdata=&quot;pageNO&quot; format=&quot;#&quot;&gt;#&lt;/span&gt;页-共&lt;span tdata=&quot;pageCount&quot; format=&quot;#&quot;&gt;#&lt;/span&gt;页&lt;/td&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tfoot&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/table&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; % endif<br />&nbsp; &nbsp; &nbsp; % endfor<br />
    




    注意:
    1. 模版只包含table标签,支持多table(多单打印)。
    2. lodop的使用方法请参看其文档。


    大功告成。

    献丑了。如需改进,有问题请 @杨振宇_





  • ActiveX只支持windows,所以本控件不适用linux,mac osx.
    是不是指客户端只能在WINDOWS上,还是服务器必须在WINDOWS上?



  • 又见大作


  • 管理员

    mako模板能重复表头么?



  • 重复表头是?

    是由lodop完成的。页眉页脚。



  • [quote author=dquo link=topic=7397.msg16900#msg16900 date=1373108877]
    ActiveX只支持windows,所以本控件不适用linux,mac osx.
    是不是指客户端只能在WINDOWS上,还是服务器必须在WINDOWS上?
    [/quote]
    sorry, 没说清楚。
    客户端不支持非Windows.



  • [quote author=Joshua link=topic=7397.msg16902#msg16902 date=1373109235]
    mako模板能重复表头么?
    [/quote]

    lodop里,addprinttable方法可以把table里面 <theader>标签转为你说的,表头,tfoot标签转换为页脚。
    tbody里,就是明细部分了,自动根据页面高度分页。

    另外lodop还支持一些标签,比如,总页数,当前页数,数字大写转换,统计,等。



  • [quote author=ccdos link=topic=7397.msg16901#msg16901 date=1373109017]
    又见大作
    [/quote]

    不敢,自己方便,也希望与人方便。


  • 管理员

    [quote author=d_yang link=topic=7397.msg16907#msg16907 date=1373119368]
    [quote author=Joshua link=topic=7397.msg16902#msg16902 date=1373109235]
    mako模板能重复表头么?
    [/quote]

    lodop里,addprinttable方法可以把table里面 <theader>标签转为你说的,表头,tfoot标签转换为页脚。
    tbody里,就是明细部分了,自动根据页面高度分页。

    另外lodop还支持一些标签,比如,总页数,当前页数,数字大写转换,统计,等。
    [/quote]

    好东西。谢谢@d_yang分享。



  • 先留记号,慢慢研究,谢谢分享 ~



  • mark,马上研究报表开发了



  • ActiveX 代码不开源的哦?
    会不会存在一些安全漏洞?
    我看API有一些关于硬件操作的东西...



  • [quote author=mrshelly link=topic=7397.msg16915#msg16915 date=1373239851]
    ActiveX 代码不开源的哦?
    会不会存在一些安全漏洞?
    我看API有一些关于硬件操作的东西...
    [/quote]

    未知。
    这个控件用两年了,本想自己写一个,但是这个确实很方便。
    如果不是为了进行硬件操作,activex就省了。 😉



  • 跟rml 区别不是很大的样子



  • 首先,非常感谢 LZ 的 分享大作。 刚好在弄打印这块,而且还真的是要用lodop来做这个。 所以受益匪浅。
    然后,这里有个问题,想跟LZ请教下,

    在使用以下我的sample.mako模板代码时,发现maktohtml2html.py文件中的 方法 format_body中,有一个问题。

    body[:-1]得到是一个空的list, 因为 body = html.findall("body"), 对于一个Html文件来说, <body>标签只有1个。 所以这个我觉得是个问题,不知道LZ是什么解决的? 我一个小打算,是直接提bug,修改openerp的源码来搞定这件事情。 不知道还有其他的方法没有?

    openerp 的源码部分:

        def format_body(self, html):
            body = html.findall('body')
            body_list = []
            footer =  self.format_footer(body[-1].getchildren())
            for b in body[:-1]:
                body_list.append(etree.tostring(b).replace('\t', '').replace('\n',''))


    mako文件的代码。(文件名不是html,在openerp报告中没有问题。)
    <html>
    <head>
    <title>test mako template</title>
    </head>
    <body>

    <table>
    order_number: 12345
    </table>

    <footer>
    </footer>
    </body>
    </html>


Log in to reply