How to get report_name in Qweb header in Odoo 10?












3















I need to show a string in the header of several reports which must change depending on the report which is being printed.



By now, I had done this:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
... Print here what I need to show in sale order reports ...
</t>
...
</template>


It worked well for me, but now, the string does not depend on the model/table, but on the printed report.



I have a model which has two different reports to print. If one is printed, I have to show 'X' in the header, if the other one is printed, I have to show 'Y' in the header. There is no difference between them, I mean, there is no attribute in the model which allows me identify them.



For example, in a previous case, despite having the same model, I was able to show the correct string due to the state field value:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
<t t-if="o.state=='draft'">
... Print Sale Quotation ...
</t>
<t t-if="o.state!='draft'">
... Print Sale Order ...
</t>
</t>
...
</template>


But in this case there is no field which helps me. Only the report name, so I need to get it from the header.



Does anyone know how to achieve this?










share|improve this question























  • Did you try the report parser, from there you can easily distinguish reports by theire names.

    – WaKo
    Nov 26 '18 at 16:34













  • Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

    – CZoellner
    Nov 26 '18 at 16:55











  • Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

    – forvas
    Nov 27 '18 at 8:23
















3















I need to show a string in the header of several reports which must change depending on the report which is being printed.



By now, I had done this:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
... Print here what I need to show in sale order reports ...
</t>
...
</template>


It worked well for me, but now, the string does not depend on the model/table, but on the printed report.



I have a model which has two different reports to print. If one is printed, I have to show 'X' in the header, if the other one is printed, I have to show 'Y' in the header. There is no difference between them, I mean, there is no attribute in the model which allows me identify them.



For example, in a previous case, despite having the same model, I was able to show the correct string due to the state field value:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
<t t-if="o.state=='draft'">
... Print Sale Quotation ...
</t>
<t t-if="o.state!='draft'">
... Print Sale Order ...
</t>
</t>
...
</template>


But in this case there is no field which helps me. Only the report name, so I need to get it from the header.



Does anyone know how to achieve this?










share|improve this question























  • Did you try the report parser, from there you can easily distinguish reports by theire names.

    – WaKo
    Nov 26 '18 at 16:34













  • Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

    – CZoellner
    Nov 26 '18 at 16:55











  • Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

    – forvas
    Nov 27 '18 at 8:23














3












3








3








I need to show a string in the header of several reports which must change depending on the report which is being printed.



By now, I had done this:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
... Print here what I need to show in sale order reports ...
</t>
...
</template>


It worked well for me, but now, the string does not depend on the model/table, but on the printed report.



I have a model which has two different reports to print. If one is printed, I have to show 'X' in the header, if the other one is printed, I have to show 'Y' in the header. There is no difference between them, I mean, there is no attribute in the model which allows me identify them.



For example, in a previous case, despite having the same model, I was able to show the correct string due to the state field value:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
<t t-if="o.state=='draft'">
... Print Sale Quotation ...
</t>
<t t-if="o.state!='draft'">
... Print Sale Order ...
</t>
</t>
...
</template>


But in this case there is no field which helps me. Only the report name, so I need to get it from the header.



Does anyone know how to achieve this?










share|improve this question














I need to show a string in the header of several reports which must change depending on the report which is being printed.



By now, I had done this:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
... Print here what I need to show in sale order reports ...
</t>
...
</template>


It worked well for me, but now, the string does not depend on the model/table, but on the printed report.



I have a model which has two different reports to print. If one is printed, I have to show 'X' in the header, if the other one is printed, I have to show 'Y' in the header. There is no difference between them, I mean, there is no attribute in the model which allows me identify them.



For example, in a previous case, despite having the same model, I was able to show the correct string due to the state field value:



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
<t t-if="o.state=='draft'">
... Print Sale Quotation ...
</t>
<t t-if="o.state!='draft'">
... Print Sale Order ...
</t>
</t>
...
</template>


But in this case there is no field which helps me. Only the report name, so I need to get it from the header.



Does anyone know how to achieve this?







xml odoo odoo-10 qweb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 9:06









forvasforvas

5,53362981




5,53362981













  • Did you try the report parser, from there you can easily distinguish reports by theire names.

    – WaKo
    Nov 26 '18 at 16:34













  • Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

    – CZoellner
    Nov 26 '18 at 16:55











  • Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

    – forvas
    Nov 27 '18 at 8:23



















  • Did you try the report parser, from there you can easily distinguish reports by theire names.

    – WaKo
    Nov 26 '18 at 16:34













  • Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

    – CZoellner
    Nov 26 '18 at 16:55











  • Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

    – forvas
    Nov 27 '18 at 8:23

















Did you try the report parser, from there you can easily distinguish reports by theire names.

– WaKo
Nov 26 '18 at 16:34







Did you try the report parser, from there you can easily distinguish reports by theire names.

– WaKo
Nov 26 '18 at 16:34















Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

– CZoellner
Nov 26 '18 at 16:55





Yes, look into render_html() you probably need to override it, to update docargs with your report as an object.

– CZoellner
Nov 26 '18 at 16:55













Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

– forvas
Nov 27 '18 at 8:23





Thank you both, I guess @EasyOdoo solution is easier than inheriting from those methods, what do you think?

– forvas
Nov 27 '18 at 8:23












1 Answer
1






active

oldest

votes


















2














I tried this and it worked hope you get the idea. First there is some
fact that I know (but not for sure) that made me came with this logic.




  1. There is no direct way to set a attribute on docs or o(RecordSet passed to report) on Qweb.

  2. We have access to context o.env.context.

  3. when you call a template inside another the last one have access to the the scope of the first template.


Instead of adding attribute why we don't just add a key to the magic attribute context using o.with_context
using the power of t-set we can add an extra key but we need to make sure we do this before
we call <t t-call="report.external_layout"> in the report template so the external_layout can find
that extra key on the context ^^



 <!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">


Now because context is frozendict instance or something like it (I'm not sure), we can use get with default
value to check if that special key is passed on the context.



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->


Or you can make it even better by making this behavior generale by just passing the value itself in the context
this will minimize number of if statements on you external_layout .



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>


So for any report that you need it to have this behavior.
if it's existing one inherit the template and make sure that you add the key before calling external_layout using x-path.



Edits:



an example of the result this is in odoo 8.0 I didn't use inherit I directly updated the remplates.



sale.order template



<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">


external layout on report



 <template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...


result is this



final result






share|improve this answer


























  • Brilliant answer, again! Thank you very much Cherif.

    – forvas
    Nov 27 '18 at 8:20











  • Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

    – EasyOdoo
    Nov 27 '18 at 11:08














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477734%2fhow-to-get-report-name-in-qweb-header-in-odoo-10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I tried this and it worked hope you get the idea. First there is some
fact that I know (but not for sure) that made me came with this logic.




  1. There is no direct way to set a attribute on docs or o(RecordSet passed to report) on Qweb.

  2. We have access to context o.env.context.

  3. when you call a template inside another the last one have access to the the scope of the first template.


Instead of adding attribute why we don't just add a key to the magic attribute context using o.with_context
using the power of t-set we can add an extra key but we need to make sure we do this before
we call <t t-call="report.external_layout"> in the report template so the external_layout can find
that extra key on the context ^^



 <!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">


Now because context is frozendict instance or something like it (I'm not sure), we can use get with default
value to check if that special key is passed on the context.



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->


Or you can make it even better by making this behavior generale by just passing the value itself in the context
this will minimize number of if statements on you external_layout .



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>


So for any report that you need it to have this behavior.
if it's existing one inherit the template and make sure that you add the key before calling external_layout using x-path.



Edits:



an example of the result this is in odoo 8.0 I didn't use inherit I directly updated the remplates.



sale.order template



<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">


external layout on report



 <template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...


result is this



final result






share|improve this answer


























  • Brilliant answer, again! Thank you very much Cherif.

    – forvas
    Nov 27 '18 at 8:20











  • Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

    – EasyOdoo
    Nov 27 '18 at 11:08


















2














I tried this and it worked hope you get the idea. First there is some
fact that I know (but not for sure) that made me came with this logic.




  1. There is no direct way to set a attribute on docs or o(RecordSet passed to report) on Qweb.

  2. We have access to context o.env.context.

  3. when you call a template inside another the last one have access to the the scope of the first template.


Instead of adding attribute why we don't just add a key to the magic attribute context using o.with_context
using the power of t-set we can add an extra key but we need to make sure we do this before
we call <t t-call="report.external_layout"> in the report template so the external_layout can find
that extra key on the context ^^



 <!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">


Now because context is frozendict instance or something like it (I'm not sure), we can use get with default
value to check if that special key is passed on the context.



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->


Or you can make it even better by making this behavior generale by just passing the value itself in the context
this will minimize number of if statements on you external_layout .



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>


So for any report that you need it to have this behavior.
if it's existing one inherit the template and make sure that you add the key before calling external_layout using x-path.



Edits:



an example of the result this is in odoo 8.0 I didn't use inherit I directly updated the remplates.



sale.order template



<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">


external layout on report



 <template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...


result is this



final result






share|improve this answer


























  • Brilliant answer, again! Thank you very much Cherif.

    – forvas
    Nov 27 '18 at 8:20











  • Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

    – EasyOdoo
    Nov 27 '18 at 11:08
















2












2








2







I tried this and it worked hope you get the idea. First there is some
fact that I know (but not for sure) that made me came with this logic.




  1. There is no direct way to set a attribute on docs or o(RecordSet passed to report) on Qweb.

  2. We have access to context o.env.context.

  3. when you call a template inside another the last one have access to the the scope of the first template.


Instead of adding attribute why we don't just add a key to the magic attribute context using o.with_context
using the power of t-set we can add an extra key but we need to make sure we do this before
we call <t t-call="report.external_layout"> in the report template so the external_layout can find
that extra key on the context ^^



 <!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">


Now because context is frozendict instance or something like it (I'm not sure), we can use get with default
value to check if that special key is passed on the context.



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->


Or you can make it even better by making this behavior generale by just passing the value itself in the context
this will minimize number of if statements on you external_layout .



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>


So for any report that you need it to have this behavior.
if it's existing one inherit the template and make sure that you add the key before calling external_layout using x-path.



Edits:



an example of the result this is in odoo 8.0 I didn't use inherit I directly updated the remplates.



sale.order template



<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">


external layout on report



 <template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...


result is this



final result






share|improve this answer















I tried this and it worked hope you get the idea. First there is some
fact that I know (but not for sure) that made me came with this logic.




  1. There is no direct way to set a attribute on docs or o(RecordSet passed to report) on Qweb.

  2. We have access to context o.env.context.

  3. when you call a template inside another the last one have access to the the scope of the first template.


Instead of adding attribute why we don't just add a key to the magic attribute context using o.with_context
using the power of t-set we can add an extra key but we need to make sure we do this before
we call <t t-call="report.external_layout"> in the report template so the external_layout can find
that extra key on the context ^^



 <!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">


Now because context is frozendict instance or something like it (I'm not sure), we can use get with default
value to check if that special key is passed on the context.



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->


Or you can make it even better by making this behavior generale by just passing the value itself in the context
this will minimize number of if statements on you external_layout .



<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>


So for any report that you need it to have this behavior.
if it's existing one inherit the template and make sure that you add the key before calling external_layout using x-path.



Edits:



an example of the result this is in odoo 8.0 I didn't use inherit I directly updated the remplates.



sale.order template



<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">


external layout on report



 <template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...


result is this



final result







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 27 '18 at 18:20

























answered Nov 26 '18 at 18:03









EasyOdooEasyOdoo

7,2392923




7,2392923













  • Brilliant answer, again! Thank you very much Cherif.

    – forvas
    Nov 27 '18 at 8:20











  • Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

    – EasyOdoo
    Nov 27 '18 at 11:08





















  • Brilliant answer, again! Thank you very much Cherif.

    – forvas
    Nov 27 '18 at 8:20











  • Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

    – EasyOdoo
    Nov 27 '18 at 11:08



















Brilliant answer, again! Thank you very much Cherif.

– forvas
Nov 27 '18 at 8:20





Brilliant answer, again! Thank you very much Cherif.

– forvas
Nov 27 '18 at 8:20













Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

– EasyOdoo
Nov 27 '18 at 11:08







Thanks you another hard question too, i'm wrong in one thing you can ckeck if an object has attribute 'some_attribute' in o forget about it LOL.

– EasyOdoo
Nov 27 '18 at 11:08






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477734%2fhow-to-get-report-name-in-qweb-header-in-odoo-10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft