odoo源生打印【web report】

https://www.odoo.com/documentation/12.0/reference/reports.html     具体的看官方文档

一、纸张格式设置:

<record id="paperformat_frenchcheck" model="report.paperformat">
    <field name="name">French Bank Check</field>
    <field name="default" eval="True"/>
    <field name="format">custom</field>
    <field name="page_height">80</field>
    <field name="page_width">175</field>
    <field name="orientation">Portrait</field>
    <field name="margin_top">3</field>
    <field name="margin_bottom">3</field>
    <field name="margin_left">3</field>
    <field name="margin_right">3</field>
    <field name="header_line" eval="False"/>
    <field name="header_spacing">3</field>
    <field name="dpi">80</field>
</record>


二、菜单按钮:
  <report
attachment_use="False"
model="product.product" #要打印模块
report_type="qweb-pdf"
id="print_product_menu_barcode"
string="打印条码"
name="product.print_template_barcode"
    file="product.print_template_barcode" #打印文件
    paperformat="product.paperformat_frenchcheck"  #打印纸张格式
/>



<img t-att-src="'/report/barcode/QR/%s' % 'My text in qr code'"/>
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s'%('QR', 'text', 200, 200)"/>  二维码

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template id="print_template_barcode">
            <t t-call="web.html_container">
                <t t-foreach="docs" t-as="o">
                    <div class="page" style="margin-top:0px">
                        <style type="text/css">
                            .gxtr >th{
                            text-align:center;
                            border-top: 1px solid #000;
                            border-left: 1px solid #000;
                            border-bottom: 1px solid #000;
                            <!--background-color:#BEBEBE;-->
                            font-size:14px;
                            }
                            .gxtr >td{
                            border-bottom: 1px solid #000;
                            border-left: 1px solid #000;
                            border-right: 1px solid #000;
                            font-size:20px;
                            display: flex;
                            <!--text-align :center;-->
                            }
                            .gxtr >tr{
                            border-bottom: 1px solid #000;
                            border-left: 1px solid #000;
                            border-right: 1px solid #000;
                            font-size:20px;
                            display: flex;
                            text-align :center;
                            }
                            .herdtd{
                            word-wrap:break-word;22%;font-size:14px;
                            }
                            .gxdiv{border-left:1px solid #000;border-bottom:1px solid #000;border-right:1px solid
                            #000;font-size:14px;}
                        </style>
                        <t t-call="web.basic_layout">
                             <table width="279" border="1">
                                <thead>
                                <tr>
                                    <td>名称</td>
                                    <td>
                                        <span t-field="o.name"/>
                                    </td>
                                    <td rowspan="3">
                                        <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s'%('QR', o.barcode, 100, 100)"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>价格</td>
                                    <td>
                                        <span t-field="o.list_price"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>代码</td>
                                    <td >
                                        <span t-field="o.barcode"/>
                                    </td>
                                </tr>
                                 <tr class="gxtr">
                                        <th>测试1</th>
                                        <th colspan="2">测试值</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr t-foreach="o.attribute_line_ids" t-as="att" class="gxtr">
                                        <td height="32" style="text-align :center;">
                                            <span t-field="att.attribute_id.name"/>
                                        </td>
                                        <td colspan="2"  style="text-align :center;">
                                            <t t-foreach="att.value_ids" t-as="val">
                                                <span t-field="val.name"/>;
                                            </t>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </t>
                    </div>
                </t>
            </t>
        </template>
    </data>
</odoo>

 
原文地址:https://www.cnblogs.com/1314520xh/p/12443834.html