Odoo Help

6

2
13 Answers
8
Avatar

Axel Mendoza

--Axel Mendoza--
13613
| 8 8 10
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
30/07/15, 08:59

Hi Yenthe

First the css that you declare in the file mylayout.css is not used because of this:

css and style declarations It's working ok, just a little more hard than expected, I just test it locally by modifying the saved view in the database for my working layout view(website module override original report layout) to add my style(ugly yeah), the scenario work by collecting the styles defined in the head of the report document, as you said is not working for the body of the report document, at least for pdf, for html is ok. The way to go is extend the report layout to add your css files or styles to the head or create a new report layout to ensure that your css is loaded in the head only for your target report template. I test it by changing the color and it works in html and pdf reports. The same apply for your needs. With that fixed you could now try again all the methods for including your custom font, including the following:

Second your custom font won't will be picked by wkhtmltopdf, but you could declare it in another way. for example:

Full explanation here:

http://blog.shahariaazam.com/use-google-web-fonts-for-wkhtmltopdf-tools/

<style type="text/css"> 
@font-face {     font-family: cool_font;     font-style: normal; font-weight: 400; src: url(data:font/opentype;charset=utf-8;base64,d09GRgABAAAAAD00AA4A---[large string ommited]----3MAuAH/hbAEjQA=) format("woff"), url(data:font/truetype;charset=utf-8;base64,AAEAAAARAQAABAAQRFNJRwAAAAEAAJUIAAA---[large string ommited]-----wAAAAAAAAAAAAEAAAAA) format("truetype");
} h1{     font-family:cool_font;     color:blue;     text-align:center;  }
</style>

7 Comments
Yenthe Van Ginneken
30/07/15, 09:20

Thanks for the reply Axel. What exactly do you mean with you can declare the same inside the report template? Do you mean to add everything between style= or? Its pretty strange that you need to base64 encode your font family by the way.. :/

Axel Mendoza
30/07/15, 09:27

I mean like using . I update my answer to include those tags. That need to be declared as part of your report template. It's rare but it's a solution

Axel Mendoza
30/07/15, 09:28

I mean style tag definition. Odoo forum delete the tag style in the previous comment. The answer is ok

Yenthe Van Ginneken
30/07/15, 09:44

@Axel thanks for the update. I did try the method of adding the CSS within the XML template but that doesn't get rendered either. Not even the color for example, so this makes me believe CSS inside the XML templates does not work?

Axel Mendoza
30/07/15, 09:49

Docs said: Useful Remarks Twitter Bootstrap and FontAwesome classes can be used in your report template Local CSS can be put directly in the template Global CSS can be inserted in the main report layout by inheriting its template and inserting your CSS

Yenthe Van Ginneken
30/07/15, 10:02

@Axel I've tried adding CSS in the latest runbot for simply centering and coloring a H1 in a report and that doesn't even work. Perhaps this never even worked in Odoo? Any ideas?

Axel Mendoza
30/07/15, 11:33

I edited my answer with the solution to load css and styles, explaining why did not work before

6
Cyril
17/01/17, 12:58

Hello

In odoo v10, it seems to be super easy... That's what we did with google font Roboto :

- Inherit css with google :

<xpath expr="." position="inside">
    <link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed" rel="stylesheet"/>
</xpath>

- Inherit the reports with font-family :

<xpath expr="//div[@class='page']" position="attributes">
    <attribute name="style">font-family: 'Roboto', sans-serif;</attribute>
</xpath>

- Inherit the header and footer with font-family :

<xpath expr="//div[@class='footer']" position="replace">
    <div class="footer" style="font-family: 'Roboto Condensed', sans-serif;">
...

It works with wkhtmltopdf 0.12.1


1 Comment
twanda AG, Ermin Trevisan
24/01/17, 11:35

Can you please explain which css file should be inherited with google? Could you provide an example of the complete xml file?

1
EasyPME
25/01/17, 03:56

Here is the complete xml for inheriting css :

<template id="my_module.report_assets_common" name="my_module report assets common" inherit_id="report.assets_common">
    <xpath expr="." position="inside">
        <link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed" rel="stylesheet"/>
    </xpath>
</template>
0
David Moreno
15/02/19, 05:46

In case someone is looking for an Odoo v12 approach:

If you just need your custom font to be rendered in your HTML reports. In your custom css file you can:

body{    
    font-family: 'Montserrat', sans-serif;
}

And then, in your assets.xml file you could inherit the report_assets_common in this way:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
        <template id="report_assets_common" name="Technical Service Assets Reports" inherit_id="web.report_assets_common">
            <xpath expr="//link[last()]" position="after">
                <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"/> /*Here your chosen Google Font or any other*/
                <link rel="stylesheet" href="your_custom_module/static/src/css/report_styles.css"/> /*This is your custom css file*/
            </xpath>
        </template>
</odoo>

Finally add both files if not already there in your __manifest__.py:

'data': [
    'views/assets.xml',
],
'css': [
    'static/src/css/report_styles.css',
],

But this doesn't work that easy with pdf rendering. In that other case, following the @Cyril concept:

 This is for PDF printing reports:


Same as before, append your new fonts to the assets:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>        
    <template id="report_assets_common" name="Technical Service Assets Reports" inherit_id="web.report_assets_common">           
        <xpath expr="//link[last()]" position="after">                 
            <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"/> /*Here your chosen Google Font or any other*/                 
            <link rel="stylesheet" href="your_custom_module/static/src/css/report_styles.css"/> /*This is your custom css file*/            
        </xpath>         
    </template>
</odoo>

You could inherit your chosen layout, in this case I'll take the external_layout_standard, and assign the styles to those part of the template you want to be affected. I'll change everything, so I'll select the header, article and the footer. Don't forget to appent to the __manifest__.py and upgrade your module after all.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <data>
        <template id="external_layout_standard" inherit_id="web.external_layout_standard">           
            <xpath expr="//div[@class='header']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath>
            <xpath expr="//div[@class='article']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath> 
            <xpath expr="//div[@class='footer']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath>
        </template>
    </data>
</odoo>
Ask a Question
Keep Informed
3 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now