I created a pdf template with form fields which are filled by Odoo when printing the quotation in the sales app.
In the base that works fine. However I created some multiline fields by overwriting the "_get_form_fields_mapping" function in the "ir_actions_report" model from Odoo.
Unfortunately line breaks are removed in the pdf field. Is there any way to avoid that and just keep the line breaks?
My code (deleted all unnecessary code):
def _get_form_fields_mapping(self, order, doc_line_id_mapping=None):
""" Dictionary mapping specific pdf fields name to Odoo fields data for a sale order.
Override this method to add new fields to the mapping.
:param recordset order: sale.order record
:rtype: dict
:return: mapping of fields name to Odoo fields data
Note: order.ensure_one()
"""
order.ensure_one()
env = self.with_context(use_babel=True).env
tz = order.partner_id.tz or self.env.user.tz or 'UTC'
lang_code = order.partner_id.lang or self.env.user.lang
form_fields_mapping = {
'test': "This is a test \n to see if \n line breaks are working.",
}
# Adding fields from each line, prefixed by the line_id to avoid conflicts
lines_with_doc_ids = set(doc_line_id_mapping.values())
for line in order.order_line.filtered(lambda sol: sol.id in lines_with_doc_ids):
form_fields_mapping.update(self._get_sol_form_fields_mapping(line))
return form_fields_mapping
In the field I created in the pdf the multiple lines flag is activated (set in Libre office and turned to pdf). De name of the field is "test" like the key in the "form_fields_mapping" dictionary.
Still the result in the pdf is:
"This is a test to see if line breaks are working." So without the line breaks.
I traced back the problem till the Odoo pdf model in "src/odoo/odoo/tools/pdf.py" and the methode "fill_form_fields_pdf(writer, form_fields)" where, just before the line "writer.updatePageFormFieldValues(page, form_fields)", the field "text" still has the line breaks in it. "updatePageFormFieldValues" is a class in the PyPDF2 library. The version of PyPDF2 installed on Odoo.sh is
Actually I got stuck at this point. The problem should, as far as I can understand, be in the code of the PyPDF library, in the pdf field settings or the settings of PyPDF2 set in the Odoo code some where. At the moment I have no idea what to do next. I hope someone can help.