Skip to Content
Menu
This question has been flagged
2 Replies
1351 Views

I have a module that makes use of a "contract" report. The issue is that in a multi-company environment, this report needs to be different for each company. How can I dinamically create a document that can be edited for each company?


As of now, the same report is used in all companies, and needs to be edited via code, or tecnical tools->reports->Qweb content.


I've thought about creating an email template but I need to print the document to be signed.


Other option is to create a blank report that just includes a single field with the "template" content, however, i need to access fields from the model, how would I escape rendering the "template" field to include fields from the model?

Avatar
Discard
Author Best Answer

I finally solved it by using email templates. 

I created a Many2one field in the model linked to mail.template so the user can choose which template to use on each record.  created a report that only called the mail.template method that converts the variables to strings:

class Contrato(models.Model):
    
    plantilla_contrato_id = fields.Many2one('mail.template')

def render_contract(self):
tpl = self.env['mail.template'].browse(self.plantilla_contrato_id.id)
data = self.env['mail.template']._render_template(tpl.body_html, 'alquileres.contrato', self.id, post_process=False)

return data

and in the report:

t-raw="o.render_contract()"

This way, I can have many email templated with the diferent contract formats.

<
Avatar
Discard
Best Answer

Hi Asis,

You may try by adding all the fields need in the same report and using the company_id as condition to show or hide the fields as you require them in the intended report.

To get the company_id try with:

company_id = self.env.company.id
Avatar
Discard
Author

Thank you! That could work, I was looking for a solution that I would have to go into code to change the wording of the contract.