Ankit
Ankit

Reputation: 69

How to print values of field variables declared inside html content?

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:

Hello ${object.partner_id.name},

PDF Report should contain:

Hello Marks,

How can I achieve this? Thanks in advance.

Upvotes: 1

Views: 1074

Answers (1)

You can do it using following method.

self.env['email.template'].render_template_batch(getattr(self,'description'),model,ids,post_process=('description'))

getattr(self,'description') : this parameter is your field name

model : your model name which you want to render runtime.

ids : Your record ids it is related to model

You can get this value in qweb reports using parser.

In parser you need to call above method and using above code render value of html field.

This may help you.

Ex:

 result=self.env['email.template'].render_template_batch(getattr(self,'description'),model,ids,post_process=('description'))

 result=tools.html_sanitize(result.get(record.id))

 result=tools.html2plaintext(result)

Upvotes: 1

Related Questions