Skip to Content
Menu
This question has been flagged

This question is a solution sample. I'm not a very experienced programmer. The main question is: Did i forget something?

Sometimes it is neccessary to use higher report resolutions than 90DPI. I found many workarounds to avoid different representations on different resolutions. I think it would be the easiest way to provide report dependend stylesheets. I have tried:

  • inherit from web.report_assets_common (Makes SCSS accessible for all reports)

  • <style> and <script> tags in report template (Maybe I'm dumb but both simply don't work with wkhtml)

  • inherit web.report_layout and add a dynamic style attribute to the html tag (No success)

then I've found a new mechanism in 13.0: update_scss().

This methon in base -> res_company.py updates an attachment named res.company.scss which will be used in reports to change company colors and font. So I inherit from res.company and wrote this:

class Company(models.Model):
   _inherit="res.company"
def update_scss(self): 
    super(Company, self).update_scss()        
    paperformat = self.paperformat_id 
    if paperformat.dpi:
        # get the scss file and decode it
        attachment = self.env['ir.attachment'].search([('name', '=', 'res.company.scss')])
        scss_data = base64.b64decode(attachment.datas).decode('utf-8')
        # update the string and overwrite the 
        scss_string = '{}\n html {{font-size: 12pt / 90 * {};}}'.format(scss_data, paperformat.dpi)
        scss_data = base64.b64encode((scss_string).encode('utf-8'))
        attachment.write({'datas': scss_data})
   return ''

I checked the appearance with several dpi values now they're nearly similar.

Do you know other solutions? By doing it this way, do you see any risks?

Avatar
Discard
Related Posts Replies Views Activity
2
Jan 18
4086
2
Jan 21
3174
1
May 19
5758
1
Sep 24
326
1
Jul 24
273