如何使html字段的表格边框(使用CKeditor编辑)可见?

时间:2015-08-13 13:44:09

标签: html ckeditor report odoo odoo-8

我试图打印用CKeditor格式化的html字段的内容。为此,我将字段note更改为html字段,如下所示:

from openerp import models, fields


class CustomSaleOrder(models.Model):
    _inherit = 'sale.order'

    note = fields.Html(
        string='Terms and conditions',
    )

我也改变了报告以打印html代码:

<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
    <xpath expr="//p[@t-field='o.note']" position="replace">
        <p t-raw="o.note" />
    </xpath>
</template>

我想在CKeditor中创建表,并在报表中显示它们(带有边框)。似乎有一个plugin of CKeditor可以做到这一点,但我不知道它是否能够正常运行或是否可以安装。

我还检查了如何在数据库中保存html字段,并使用属性border="1"保存表格:

<table border="1" cellpadding="1" cellspacing="1" style="width:500px">
    <tbody>
        <tr>
            <td>cell 1</td>
[...]

如果我将报告打印为html报告,则表格可见,但如果我将报告打印为pdf,则边框不可见。

有没有一种简单的方法可以实现这一目标?

1 个答案:

答案 0 :(得分:0)

好吧,我解决了这个问题:

首先,我在报告中添加了一个类和自定义样式:

<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
    <xpath expr="//p[@t-field='o.note']" position="replace">
        <div class="ckeditor_field">
            <p t-raw="o.note"  />
        </div>
    </xpath>
</template>

<template id="custom_sale_order_style" inherit_id="report.layout">
    <xpath expr="//style" position="after">
        <style type="text/css">
            .ckeditor_field table {
                margin: 12px 0px 12px 0px;
            }

            .ckeditor_field table td {
                border: 1px solid black;
                vertical-align: middle;
                padding: 8px 10px 8px 10px;
            }

            .ckeditor_field p {
                line-height: 1;
            }

        </style>
    </xpath>
</template>  

我还添加了另一个类,使用相同或相似的CSS添加到视图中。当我保存字段时,我这样做是为了查看表格:

<record id="view_order_form_wtd" model="ir.ui.view">
    <field name="name">sale.order.form.wtd</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">   
        <field name="note" position="replace">
            <field name="note" class="note_wtd" widget="html" />
        </field>
    </field>
</record>