----------------------------
step 1、把报表类型由原来的qweb-pdf改成qweb-html:
<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"
/>
step 2、根据康虎云报表的数据规范生成报表数据:
报表数据格式如下(json格式,详细说明请参考康虎云报表相关帮助文档):
=====================================================
<script type="text/javascript">
var cfprint_addr = "127.0.0.1"; //打印服务器监听地址
var _delay_close = -1; //打印完成后关闭窗口的延时时长(毫秒), -1则表示不关闭
/**定义主表结构**/
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":[ ]
};
/**定义从表结构**/
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":[ ]
};
<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)"/>",
"包装种类":"",
"车号":"",
"柜号":""
});
<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"}'/>"
});
</t>
</t>
//下面把所有表合并到一个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>
=====================================================
以上数据文件中的数据项,可以根据原来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, "no_tag_br": true,"data_type": "raw"}' />
将生成:
中国福建省厦门市 361000,远海码头便利店
step 3、自动输出到打印机
如果生成的json字符串名为 _reportData 且没有语法错误,则会自动输出到打印机;
如果没有打印,则先用浏览器的脚本调试功能打开看一下,有没有脚本错。