Skip to Content
Menu
This question has been flagged

Hi everyone,

I created a qweb-pdf template that works pretty (PDF file is generate without error) well except for one thing : a field (customer_name) value is not displayed.


This is report template code snippet :

..
t-if="customer_name">
The custom value is: t-esc="customer_name"/>

..

I call this qweb-pdf from JS file (on POS environment) like this : 

..
await this.env.pos.do_action('my_module.pos_custom_report', {
additional_context: {
active_ids: [119], // 119 is value for my test..
customer_name: this.props.customer_name, // This is the value I want to display in my customer_name field on the report
},
});
..


In _get_report_values method, when i print context, i don't see 'customer_name' i pass in my JS. So i don't know how to pass value i don't see here inside my report template.

..
@api.model
def _get_report_values
(self, docids, data=None):
print("a+A _get_report_values _context :", self._context)

docs = self.env['pos.order'].browse(docids)

return {
'doc_ids': docids,
'doc_model': 'pos.order',
'docs'
: docs,
}
..

How can i do to pass customer_name from JS to my custom report template ?

What am I missing ?

Thanks for any help !

Avatar
Discard
Best Answer

Hi,

Instead of calling "customer_name" from the template try calling "o.partner_id.name" or "itrator_variable_of_docs.partner_id.name"

if the above method doesn't work, Instead of passing value from js, we can do it from python as,

customer_names = docs.mapped('partner_id.name')

"customer_names" will have the list of the customer names

then change the return into,

return {
'doc_ids' : docids,
'doc_model' : 'pos.order',
'docs' : docs ,
'data' : customer_names,
}

then try calling "data" from template, you will be able to receive values of the customer_names variable

Regards

Avatar
Discard
Author

Thank you for your answer.

I understand what you are saying, but customer_name I am trying to display in my template is from JS. It's not a value I'm storing in a field. It's the value of an input field that I've added to the POS.
So when the input field is filled in and I click a button, I generate a report with my template.

Do you understand what I am saying ?

P.S : The name of the variable may be a bit misleading

Related Posts Replies Views Activity
0
Mar 23
1085
1
May 16
7106
1
Nov 24
2991
0
May 24
506
1
Apr 24
1021