Odoo Help

Welcome!

This community 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.

0

Odoo 8 Reporting : Change default "Total" label

By
Yassine TEIMI
on 12/21/15, 11:56 AM 579 views

I want to change this total label to "Average", How it could be possible ?

-------------------------------------------------------------------------EDIT----------------------------------------------------------------------------------------------

@Axel :

Here is the error : JS test results raising error

And Here is my code :

__openerp__.py

{ 'name''HR appraisals advanced management (Survey enhancements included)': ,
'description':'Advanced appraisals management' ,
'author':'Yassine TEIMI ,
'depends': ['hr_evaluation','survey','web_graph'],
  'data': ['views/survey_templates.xml','views/survey_result.xml','report/hr_evaluation_report_extension_view.xml','static/src/xml/assets_backend.xml'],
}

change_total_label.js : 

(function () {

'use strict';

var _lt = openerp.web._lt;

var _t = openerp.web._t;

openerp.web_graph.PivotTable.include({

find_or_create_header: function (headers, path, data_pt) {

var self = this;

var hdr = _.find(headers, function (header) {

return self.isEqual(path, header.path);

});

if (hdr) {

return hdr;

}

if (!path.length) {

var pivot_header = 'Total';

if(self.context.pivot_header != undefined){

pivot_header = self.context.pivot_header;

}

hdr = this.make_header({title: _t(pivot_header)});

headers.push(hdr);

return hdr;

}

hdr = this.make_header({

path:path,

domain:data_pt.model._domain,

title: _t(_.last(path))

});

var parent = _.find(headers, function (header) {

return self.isEqual(header.path, _.initial(path, 1));

});

var previous = parent.children.length ? _.last(parent.children) : parent;

headers.splice(headers.indexOf(previous) + 1, 0, hdr);

parent.children.push(hdr);

return hdr;

},

});

})();

assets_backend.xml : 

<template id="assets_backend" name="web_graph assets" inherit_id="web.assets_backend">

<xpath expr="." position="inside">

<script type="text/javascript" src="/hr_appraisals_adv/static/src/js/change_total_label.js"></script>

</xpath>

</template>

my reporting action, where I need to passe the pivot header : 

<record id="action_evaluation_goals_reaching" model="ir.actions.act_window">
<field name="name">Atteinte des objectifs</field>
<field name="res_model">hr.evaluation.report.goals</field>
<field name="view_type">form</field>
<field name="view_mode">graph</field>
<field name="search_view_id" ref="view_goals_reaching_search"/>
<field name="context">{'pivot_header': 'Moyenne'}</field> <!-- just added here the label in french -->
</record>
1

Axel Mendoza

--Axel Mendoza--
10308
| 7 7 8
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 an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/21/15, 1:14 PM

You need to do it by extending the widget because that label it's hard-coded in the widget. For that you need to register your js file in the web.assets_backend template like:

<template id="assets_backend" name="web_graph assets" inherit_id="web.assets_backend">

<xpath expr="." position="inside">

<script type="text/javascript" src="/your_module/static/src/js/your_file.js"></script>

</xpath>

</template>

In your_file.js you need to extend the widget like:

openerp.hr_appraisals_adv = function (openerp) {

var _lt = openerp.web._lt;

var _t = openerp.web._t;

openerp.web_graph.PivotTable.include({

find_or_create_header: function (headers, path, data_pt) {

var self = this;

var hdr = _.find(headers, function (header) {

return self.isEqual(path, header.path);

});

if (hdr) {

return hdr;

}

if (!path.length) {

var pivot_header = 'Total';

if(self.context.pivot_header != undefined){

pivot_header = self.context.pivot_header;

}

hdr = this.make_header({title: _t(pivot_header)});

headers.push(hdr);

return hdr;

}

hdr = this.make_header({

path:path,

domain:data_pt.model._domain,

title: _t(_.last(path))

});

var parent = _.find(headers, function (header) {

return self.isEqual(header.path, _.initial(path, 1));

});

var previous = parent.children.length ? _.last(parent.children) : parent;

headers.splice(headers.indexOf(previous) + 1, 0, hdr);

parent.children.push(hdr);

return hdr;

},

});

};

With that extension you can change the label of the Total pivot header by put the value under the key 'pivot_header' of the context dict of the action that load your graph view.
For example:

<record model="ir.actions.act_window" id="your_record_id">

<field name="name">Model View Name</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">your_model</field>

<field name="view_type">form</field>

<field name="view_mode">graph,tree,form</field>

<field name="context">{'pivot_header': 'Average'}</field>

</record>

Result:

@Axel, I've tested it and gave this js error : Uncaught TypeError: viewclass is not a function, located on : /js/web.assets_backend/a7b03df:3143

Yassine TEIMI
on 12/23/15, 5:38 AM

Could you run it again but with developer mode active and post the error? developer mode will throw you a more accurate error message. I test that solution locally and get it working. Try to post your code too

Axel Mendoza
on 12/23/15, 6:14 AM

I posted the error by editing my question.

Yassine TEIMI
on 12/23/15, 7:28 AM

Did you have a dependency with the module web_graph in your module __openerp__.py??

Axel Mendoza
on 12/23/15, 7:33 AM

Added the dependacy, restarted the server, here is the error raised after running test from developper mode : http://prntscr.com/9hmcem

Yassine TEIMI
on 12/23/15, 7:43 AM

See my edited question for code details.

Yassine TEIMI
on 12/23/15, 10:00 AM

I update the js file of my answer to properly fix that error.

Axel Mendoza
on 12/23/15, 12:16 PM

Great it works fine, Thanks a lot, I really appreciate your help!

Yassine TEIMI
on 12/23/15, 5:19 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/21/15, 11:56 AM
Seen: 579 times
Last updated: 12/23/15, 5:20 PM