index.html 12.3 KB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>

<body>
<section class="oe_container">
    <div class="oe_row oe_spaced">
        <h2 class="oe_slogan" style="color:#875A7B;">康虎云报表</h2>
        <h3 class="oe_slogan">你只负责收集数据,打印的事我来</h3>
        <div class="oe_span12">
            <div class=""> <!-- oe_demo oe_picture oe_screenshot -->
                <h2>康虎云报表基础模块</h2>
                <div>
                    ============================<br/>
                    基于康虎云报表的打印功能必须依赖此模块。
                </div>
                <div>
                    本模块主要功能:<br/>
                    ----------------------------<br/>
                    <ul>
                        <li>引入康虎云报表所需的javascript库</li>
                        <li>实现打印模板管理功能,模板可以存入数据库,便于统一管理(从菜单  设置--技术--报告--康虎云报表 进入)</li>
                        <li>增加了根据原QWeb报表取值功能,该功能按QWeb模板中的方式取值,但把HTML去掉,否则数据不干净可能导打印失败</li>
                        <li>(功能持续增加中...)</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="oe_container oe_dark">
    <div class="oe_row oe_spaced">
        <h2 class="oe_slogan" style="color:#875A7B;">怎样使用康虎云报表</h2>
        <h3 class="oe_slogan">康虎云报表概要用法.</h3>
    </div>
    <div class="oe_row">
        <div class="oe_span12 oe_mt32">
<pre>
----------------------------<br/>
<b>step 1、把报表类型由原来的qweb-pdf改成qweb-html:</b><br/>
&lt;report
    string="Warehouse Checklist"
    id="action_report_warehouse_checklist"
    model="stock.picking"
    report_type="qweb-html"     &lt;!-- 这里由原来的 qweb- 改为 qweb-html --&gt;
    name="stock_cf.report_warehousechecklist"
    file="stock_cf.report_warehousechecklist"
/&gt;
<br/>

<b>step 2、根据康虎云报表的数据规范生成报表数据:</b><br/>
报表数据格式如下(json格式,详细说明请参考康虎云报表相关帮助文档):<br/>
=====================================================  <br/>
&lt;script type="text/javascript"&gt;<br/>
var cfprint_addr = "127.0.0.1"; //打印服务器监听地址
var _delay_close = -1;          //打印完成后关闭窗口的延时时长(毫秒), -1则表示不关闭
<br/>
/**定义主表结构**/  <br/>
var _tablePack = {
  "Name": "Pack",
  "Cols":[
    { "type": "str", "size": 255, "name": "仓库", "required": false },
    { "type": "str", "size": 50, "name": "供应商", "required": false },
    { "type": "str", "size": 30, "name": "日期", "required": false },
    { "type": "str", "size": 255, "name": "入库单号", "required": false },
    { "type": "str", "size": 30, "name": "采购单号", "required": false },
    { "type": "int", "size": 0, "name": "件数", "required": false },
    { "type": "str", "size": 20, "name": "包装种类", "required": false },
    { "type": "str", "size": 30, "name": "车号", "required": false },
    { "type": "str", "size": 30, "name": "柜号", "required": false }
  ],
  "Data":[ ]
};  <br/>
  <br/>
/**定义从表结构**/  <br/>
var _tablePackLines = {
  "Name": "PackLines",
  "Cols":[
    { "type": "str", "size": 30, "name": "入库单号", "required": false },
    { "type": "str", "size": 255, "name": "产品", "required": false },
    { "type": "str", "size": 30, "name": "条形码", "required": false },
    { "type": "float", "size": 0, "name": "采购数量", "required": false },
    { "type": "float", "size": 0, "name": "实际数量", "required": false },
    { "type": "str", "size": 20, "name": "计量单位", "required": false },
  ],
  "Data":[ ]
};  <br/>
&lt;t t-foreach="docs" t-as="o"&gt;
/*增加主表记录*/
_tablePack.Data.push(
{
  "仓库":"&lt;span t-field="o.picking_type_id.warehouse_id.partner_id" t-field-options='{"widget": "contact", "fields": ["name"], "no_marker": true, "no_tag_br": true, "data_type": "raw"}' /&gt;",
  "供应商":"&lt;t t-if="o.partner_id" name="partner_header"&gt;&lt;span t-field="o.partner_id" t-field-options='{"widget": "contact", "fields": ["name"], "no_marker": true, "no_tag_br": true, "data_type": "raw"}' /&gt;&lt;/t&gt;",
  "日期":"&lt;t t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/&gt;",
  "入库单号":"&lt;t t-esc="o.name" class="mt0"/&gt;",
  "采购单号":"&lt;t t-if="o.origin"&gt;&lt;t t-esc="o.origin"/&gt;&lt;/t&gt;",
  "件数":"&lt;t t-esc="sum(pack_operation.product_qty for pack_operation in o.pack_operation_ids)"/&gt;",
  "包装种类":"",
  "车号":"",
  "柜号":""
});
  <br/>
&lt;t t-foreach="o.move_lines" t-as="move"&gt;
/**增加从表记录**/
_tablePackLines.Data.push(
{
  "入库单号":"&lt;t t-esc="o.name" class="mt0"/&gt;",
  "产品":"&lt;span t-field="move.product_id" t-field-options='{"data_type":"raw"}'/&gt;",
  "条形码":"&lt;t t-if="move.product_id and move.product_id.ean13"&gt;&lt;span t-field="move.product_id.ean13" t-field-options='{"data_type":"raw"}'/&gt;&lt;/t&gt;",
  "采购数量":"&lt;t t-esc="move.product_uom_qty"/&gt;",
  "实际数量":"",
  "计量单位":"&lt;span t-field="move.product_id.uom_id" t-field-options='{"data_type":"raw"}'/&gt;"
});  <br/>
    &lt;/t&gt;
&lt;/t&gt;
  <br/>
//下面把所有表合并到一个json中
var _data = {"template": "warehouse_checklist.fr3", "ver": 4, "Copies": 1, "Duplex": 0, "Tables":[]};
_data["Tables"].push(_tablePack);
_data["Tables"].push(_tablePackLines);
var _reportData = JSON.stringify(_data);  //转成json字符串

console.log(_reportData);
//生成数据之后,在cfprint_ext.js中会自动调用进行打印
&lt;/script&gt;  <br/>
=====================================================  <br/>
以上数据文件中的数据项,可以根据原来QWeb报表模板中的数据项生成,对于关联字段需要生成字段不带HTML标签的内容,
可以在 t-field-options 中增加 data_type属性来指定输出所需要格式:
 data_type = raw : 输出纯文本,不同数据项间使用逗号分隔

示例如下:
    &lt;address t-field="o.move_lines[0].partner_id" t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true, <span style="color:#FF0000; font-weight:bold;">"data_type": "raw"</span>, "no_tag_br": true}' /&gt;<br/>
将生成:
中国福建省厦门市 361000,远海码头便利店
<br/>

<b>step 3、自动输出到打印机</b><br/>
如果生成的json字符串名为 _reportData 且没有语法错误,则会自动输出到打印机;  <br/>
如果没有打印,则先用浏览器的脚本调试功能打开看一下,有没有脚本错。 <br/>
</pre>
        </div>
    </div>
</section>

<section class="oe_container oe_dark">
    <div class="oe_row oe_spaced">
        <h2 class="oe_slogan" style="color:#875A7B;">打印模板服务端统一管理</h2>
        <h3 class="oe_slogan">把打印模板保存在数据库中.</h3>
    </div>
    <div class="oe_row">
        <div class="oe_span12 oe_mt32">
            <pre>
<b>step 1、把模板上传到数据库:</b><br/>
从菜单  设置--技术--报告--康虎云报表 进入模板管理功能,其中:<br/>
<ul>
    <li>模板ID: 是用以区分模板的唯一标识,最后根据该ID取用模板</li>
    <li>名称: 是便于识别模板的名称</li>
    <li>说明:是对模板用途或其他信息的说明</li>
    <li>模板:上传的模板内容</li>
    <li>预览图:是便于了解模板具体格式的一个预览效果截图</li>
</ul>
<img src="image1.png" style="max-width: 700px;"><br/>
<img src="image2.png" style="max-width: 700px"><br/>
<img src="image3.png" style="max-width: 700px">
<br/><br/>
<b>step 2、从数据库取用模板:</b><br/>
康虎云报表支持客户端模板也支持服务端模板,客户端模板是默认的方式:<br/>
客户端模板:<br/>
{<br/>
    "template": "report_saleorder.fr3",  /*模板保存在客户端 cfprint.exe目录下templates目录下*/<br/>
    "ver": 4, <br/>
    "Copies": 1, <br/>
    "Duplex": 0, <br/>
    "Tables":[]<br/>
}<br/><br/>
服务端模板:<br/>
{
    "template": "base64: &lt;这里放模板Base64内容&gt;",
    "ver": 4, <br/>
    "Copies": 1, <br/>
    "Duplex": 0, <br/>
    "Tables":[]<br/>
}<br/><br/><br/>

这里主要介绍服务端模板,可以通过两种方式从数据库中取出模板数据:<br/>
从数据库中获取打印模板方法1(调用简短方法):<br/>
{"template": "base64:<span style="color:red">&lt;t t-esc="get_cf_template(user.env, '12345')" /&gt;</span>", "ver": 4, "Copies": 1, "Duplex": 0, "Tables":[]}
<br/><br/>
从数据库中获取打印模板方法2(直接查询法):<br/>
{"template": "base64:<span style="color:red">&lt;t t-esc="user.env['cf.template'].search([('templ_id', '=', '12345')], limit=1).template" /&gt;</span>", "ver": 4, "Copies": 1, "Duplex": 0, "Tables":[]}<br/><br/>

</pre>
        </div>
    </div>
</section>



<section class="oe_container oe_dark">
    <div class="oe_row oe_spaced">
        <h2 class="oe_slogan" style="color:#875A7B;">在模板中可直接使用的工具函数和对象</h2>
        <h3 class="oe_slogan">提供一些在模板中常用的工具函数和对象.</h3>
    </div>
    <div class="oe_row">
        <div class="oe_span12 oe_mt32">
            <pre>
<b>1、获取保存在数据库中的模板:</b>
get_cf_template(env, templ_id)
说明:
  根据env和模板ID获取保存在数据库中的模板。

参数:
  env: 当前环境对象,可直接通过 user.env 获得
  templ_id:模板id,在把模板保存到数据库时指定

示例:
  &lt;t t-esc="cf_template(user.env, 'cf.sale.order')" /&gt;

<b>2、把金额转成中文:</b>
get_cn_currency(value, capital=True, prefix=u'人民币', postfix=u'元'):
说明:
  把金额转成中文。

参数:
  value: 数字金额
  capital: 是否显示大写汉字(小写:一、二...,大写:壹、贰、叁...)
  prefix: 金额前缀
  postfix: 金额后缀(单位)

示例:
  &lt;t t-esc="_convert_cn_currency(1234.56, True, '人民币', '圆')" /&gt;

<b>3、把UTC时间转成本地时间:</b>
get_local_time(value):
说明:
  把UTC时间转成本地时间。
  与 context_timestamp 相同。

参数:
  value: UTC时间值

示例:
  &lt;t t-esc="get_local_time(order.date_order).strftime('%Y-%m-%d %H:%M:%S')"/&gt;

<b>4、把UTC时间转成本地时间:</b>
context_timestamp(value):
说明:
  把UTC时间转成本地时间。
  与 context_timestamp 相同。

参数:


示例:
  &lt;t t-esc="context_timestamp(order.date_order).strftime('%Y-%m-%d %H:%M:%S')"/&gt;

<b>5、python自带的time工具函数:</b>
context_timestamp(value):
说明:
  python自带的time工具文件,里面有一堆时间处理函数

参数:
  请参考python自带的time.py文件

示例:


<b>6、user对象:</b>
说明:
  当前user对象。
  可以通过该对象获得env对象,甚至可以在模板中直接查询记录。

参数:


示例:
  &lt;t t-esc="user.id"/>  &lt;!-- 用户ID --&gt;
  &lt;t t-esc="user.name"/>  &lt;!-- 用户姓名 --&gt;
  &lt;t t-esc="(user.env['sale.order'].search([('state','=','done')],limit=1)).name"/&gt;  &lt;!-- 直接在模板中查询订单并显示订单号 --&gt;

<b>7、res_company对象:</b>
说明:
  当前用户所在的company对象。
  该对象也可以象user对象一样获得env对象,甚至可以在模板中直接查询记录。

参数:


示例:
  &lt;t t-esc="res_company.logo"/&gt;  &lt;!-- 公司logo --&gt;
  &lt;t t-esc="(res_company.env['res.partner'].search([('name','=','康虎软件工作室')],limit=1)).website"/>  &lt;!-- 直接在模板中查询康虎云报表的网站地址 --&gt;

<b>8、website对象:</b>
说明:
  website对象(如果request中没有website属性,则是None)

参数:


示例:


<b>8、web_base_url对象:</b>
说明:
  配置信息中的web.base.url值(网站base URL)

参数:


示例:


</pre>
        </div>
    </div>
</section>

<section class="oe_container oe_separator">
</section>
</body>
</html>