Odoo Help

0

Show or hide pdf report qweb block depending on being in last page or not

By
E.M.
on 1/30/16, 8:44 PM 665 views

I know this thread has been covered in the past. However, it seems that given solutions are not working.

I have tried to modify subst function from report module without success. I am using a custom report module.

Any tips on how to achieve this in Odoo v8?

var operations = {

'bottom-page': function (elt) { elt.style.visibility = (vars.page === vars.topage) ? "visible" : "hidden"; },

};

for (var klass in operations) {

var y = document.getElementsByClassName(klass);

for (var j=0; j<y.length; ++j) operations[klass](y[j]);

}

<div class="bottom-page">

1
Cyrus Waithaka
On 2/1/16, 6:12 PM

Its always nice to make changes using a custom module instead of editing the core modules. That way, you will be able to debug your issues. Here is what works for me:

 /custom_module/static/src/js/subst.js   

function subst() {
var vars = {};
var x = document.location.search.substring(1).split('&');
for (var i in x) {
var z = x[i].split('=', 2);
vars[z[0]] = unescape(z[1]);
}
var x=['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j=0; j<y.length; ++j)
y[j].textContent = vars[x[i]];
}
var operations = {
'last-page': function (elt) {
elt.style.visibility = (vars.page === vars.topage) ? "visible" : "hidden";
},
'first-page': function (elt) {
elt.style.display = (vars.page == "1") ? "initial" : "none";
},
'other-page': function (elt) {
elt.style.display = (vars.page != "1") ? "initial" : "none";
},
};
for (var klass in operations) {
var y = document.getElementsByClassName(klass);
for (var j=0; j<y.length; ++j)
operations[klass](y[j]);
}
}

XML to replace enque subst.js using custom_module:

  <template id="minimal_layout" inherit_id="report.minimal_layout">    
<xpath expr="//script" position="replace">
<script src='/custom_module/static/src/js/subst.js'></script>
</xpath>
</template>

You can then use class="first-page" and class="other-page" in your views. 


PS. Some older versions of the report module will enqueue the subst.js differently. Refer to that if you get an "id not found in view" error.


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 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: 1/30/16, 8:44 PM
Seen: 665 times
Last updated: 2/2/16, 3:58 PM