Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
12595 Lượt xem

I have created html field in the form view. Then user will add content in that field. The content will have some field variables of form view same as we declare in email template. Then user will print pdf report and that report should display values instead of the variables.


-Example Html field content :


Hello ${object.employee_id.name},

Your amount ${object.employee_id.amount}


____________________


- PDF Report should contain:


Hello Marks,

Your amount 500



How can I achieve this? Thanks in advance.

Ảnh đại diện
Huỷ bỏ
Tác giả

the problem is not to print the Html field

it is to display the variables that is in this field Html

as the example

Câu trả lời hay nhất

hello Bouabaker, try this (odoo 11):


from odoo.addons.mail.models import mail_template

def method_name(self):

        converted_content = mail_template.mako_template_env.from_string(<your_html_content>).render({'object': object_value,})

        return converted_content

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi Farhat, Thanks ,

but in XML What I put ?

In your report xml file, call the method with:

<t t-raw="method_name()"/>

Hi Farhat, Newbie here

What should i put in object_value ? Thanks

Câu trả lời hay nhất

hello, your code is perfect but while you print the HTML field value into pdf report, print like below code.

<span t-raw="doc.your_html_field"/>


Ảnh đại diện
Huỷ bỏ
Tác giả

thanks Mitul , the problem is to print variable that are in this field HTML ,as the example as in the question

Câu trả lời hay nhất

Hello Bouabaker,

If you want to print your HTML filed in Your PDF report you can add below code :

<span t-field="doc.yourhtmlfiled"/>

i think it's help you.

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi Manish , the problem is not to print the Html field

it is to display the variables that is in this field Html

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 11 22
3171
2
thg 5 21
5307
1
thg 9 24
4364
0
thg 1 24
1558
0
thg 1 24
1253