Skip to Content
Menu
This question has been flagged
1 Reply
6504 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>
Avatar
Discard
Best Answer

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:

Avatar
Discard
Author

@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

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

Author

I posted the error by editing my question.

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

Author

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

Author

See my edited question for code details.

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

Author

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

Related Posts Replies Views Activity
0
Feb 21
2020
0
Jul 17
2325
1
Nov 24
111
0
Aug 24
237
0
Apr 24
402