Odoo Help

0

Odoo 8 Reporting : Change default "Total" label

By
Yassine TEIMI
on 12/21/15, 11:56 AM 1,414 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
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

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 E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

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