index.html
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!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/>
<report
string="Warehouse Checklist"
id="action_report_warehouse_checklist"
model="stock.picking"
report_type="qweb-html" <!-- 这里由原来的 qweb- 改为 qweb-html -->
name="stock_cf.report_warehousechecklist"
file="stock_cf.report_warehousechecklist"
/>
<br/>
<b>step 2、根据康虎云报表的数据规范生成报表数据:</b><br/>
报表数据格式如下(json格式,详细说明请参考康虎云报表相关帮助文档):<br/>
===================================================== <br/>
<script type="text/javascript"><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/>
<t t-foreach="docs" t-as="o">
/*增加主表记录*/
_tablePack.Data.push(
{
"仓库":"<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"}' />",
"供应商":"<t t-if="o.partner_id" name="partner_header"><span t-field="o.partner_id" t-field-options='{"widget": "contact", "fields": ["name"], "no_marker": true, "no_tag_br": true, "data_type": "raw"}' /></t>",
"日期":"<t t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/>",
"入库单号":"<t t-esc="o.name" class="mt0"/>",
"采购单号":"<t t-if="o.origin"><t t-esc="o.origin"/></t>",
"件数":"<t t-esc="sum(pack_operation.product_qty for pack_operation in o.pack_operation_ids)"/>",
"包装种类":"",
"车号":"",
"柜号":""
});
<br/>
<t t-foreach="o.move_lines" t-as="move">
/**增加从表记录**/
_tablePackLines.Data.push(
{
"入库单号":"<t t-esc="o.name" class="mt0"/>",
"产品":"<span t-field="move.product_id" t-field-options='{"data_type":"raw"}'/>",
"条形码":"<t t-if="move.product_id and move.product_id.ean13"><span t-field="move.product_id.ean13" t-field-options='{"data_type":"raw"}'/></t>",
"采购数量":"<t t-esc="move.product_uom_qty"/>",
"实际数量":"",
"计量单位":"<span t-field="move.product_id.uom_id" t-field-options='{"data_type":"raw"}'/>"
}); <br/>
</t>
</t>
<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中会自动调用进行打印
</script> <br/>
===================================================== <br/>
以上数据文件中的数据项,可以根据原来QWeb报表模板中的数据项生成,对于关联字段需要生成字段不带HTML标签的内容,
可以在 t-field-options 中增加 data_type属性来指定输出所需要格式:
data_type = raw : 输出纯文本,不同数据项间使用逗号分隔
示例如下:
<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}' /><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: <这里放模板Base64内容>",
"ver": 4, <br/>
"Copies": 1, <br/>
"Duplex": 0, <br/>
"Tables":[]<br/>
}<br/><br/><br/>
这里主要介绍服务端模板,可以通过两种方式从数据库中取出模板数据:<br/>
从数据库中获取打印模板方法1(调用简短方法):<br/>
{"template": "base64:<span style="color:red"><t t-esc="get_cf_template(user.env, '12345')" /></span>", "ver": 4, "Copies": 1, "Duplex": 0, "Tables":[]}
<br/><br/>
从数据库中获取打印模板方法2(直接查询法):<br/>
{"template": "base64:<span style="color:red"><t t-esc="user.env['cf.template'].search([('templ_id', '=', '12345')], limit=1).template" /></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,在把模板保存到数据库时指定
示例:
<t t-esc="cf_template(user.env, 'cf.sale.order')" />
<b>2、把金额转成中文:</b>
get_cn_currency(value, capital=True, prefix=u'人民币', postfix=u'元'):
说明:
把金额转成中文。
参数:
value: 数字金额
capital: 是否显示大写汉字(小写:一、二...,大写:壹、贰、叁...)
prefix: 金额前缀
postfix: 金额后缀(单位)
示例:
<t t-esc="_convert_cn_currency(1234.56, True, '人民币', '圆')" />
<b>3、把UTC时间转成本地时间:</b>
get_local_time(value):
说明:
把UTC时间转成本地时间。
与 context_timestamp 相同。
参数:
value: UTC时间值
示例:
<t t-esc="get_local_time(order.date_order).strftime('%Y-%m-%d %H:%M:%S')"/>
<b>4、把UTC时间转成本地时间:</b>
context_timestamp(value):
说明:
把UTC时间转成本地时间。
与 context_timestamp 相同。
参数:
略
示例:
<t t-esc="context_timestamp(order.date_order).strftime('%Y-%m-%d %H:%M:%S')"/>
<b>5、python自带的time工具函数:</b>
context_timestamp(value):
说明:
python自带的time工具文件,里面有一堆时间处理函数
参数:
请参考python自带的time.py文件
示例:
略
<b>6、user对象:</b>
说明:
当前user对象。
可以通过该对象获得env对象,甚至可以在模板中直接查询记录。
参数:
无
示例:
<t t-esc="user.id"/> <!-- 用户ID -->
<t t-esc="user.name"/> <!-- 用户姓名 -->
<t t-esc="(user.env['sale.order'].search([('state','=','done')],limit=1)).name"/> <!-- 直接在模板中查询订单并显示订单号 -->
<b>7、res_company对象:</b>
说明:
当前用户所在的company对象。
该对象也可以象user对象一样获得env对象,甚至可以在模板中直接查询记录。
参数:
无
示例:
<t t-esc="res_company.logo"/> <!-- 公司logo -->
<t t-esc="(res_company.env['res.partner'].search([('name','=','康虎软件工作室')],limit=1)).website"/> <!-- 直接在模板中查询康虎云报表的网站地址 -->
<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>