8

How can I add css files to my custom module to change xml views? I found this post but the solution is not working.

I want modify all the elements from my module, such as forms, lists, inputs, etc.

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
aispobla
  • 143
  • 1
  • 1
  • 8

1 Answers1

11
  1. You must create the css file in this route: /module_name/static/src/css/module_name.css. Example of file:

     .openerp .classname{
         margin: 12px 0px 12px 0px;
     }
    
  2. Create the file /module_name/views/module_name.xml with this content:

     <?xml version="1.0"?>
     <openerp>
         <data>
             <template id="assets_backend" name="module_name assets" inherit_id="web.assets_backend">
                 <xpath expr="." position="inside">
                     <link rel="stylesheet" href="/module_name/static/src/css/module_name.css"/>
                 </xpath>
             </template>
         </data>     
     </openerp>
    
  3. Add the xml file to your __openerp.__py

     'data': [
         'views/module_name.xml',
     ],
    
  4. Add the class to the elements in the view

     <div class="classname">                            
         <field name="field_name" class="other_class"/>
     </div>
    
ChesuCR
  • 9,352
  • 5
  • 51
  • 114
  • Thanks ChesuCR, it works. Other question, is mandatory put inherit_id="web.assets_backend"? And always is web.assets_backend? The name attribute is convention write 'module_name assets' or 'assets' not is mandatory? – aispobla Sep 30 '15 at 06:46
  • `inherit_id="web.assets_backend"` is mandatory, if you want to add styles to reports, for example, you must inherit from another template. I think the name field is not mandatory to write it like that, but if you check how is written in the rest of the modules, most of them are like that – ChesuCR Sep 30 '15 at 08:15
  • It will apply on whole ERP including all form views and all tree views, how to restrict it one module only? – Sabir Mustafa Jul 27 '17 at 08:37
  • You can add css classes to the objects that you would like to change as I wrote in my answer – ChesuCR Jul 27 '17 at 08:46