Skip to Content
Menu
This question has been flagged
1 Reply
3101 Views

Hi,

i want generate a PDF with bar char in odoo 15.

can i help me?

https://miro.medium.com/max/1400/1*bFUKtr4h4mzmY5uHuEz_zA.png

I want print this graph in PDF report but don't have find a documentation or example for include in pdf.


is there anyone to help me or show some example?

thanks a lot 

Avatar
Discard

Hello, did you find any solution?

Best Answer

Hi,

If you are using the content by passing a js file try to use rpc or Ajax call and try to update the current value (add all values with classes)  in a variable
I'd just added an example for a chart view, you can use your own div and table classes of the bar/ any graphical representation

Js:

$.ajax({
                url: '/get/parent/child',
                type: 'POST',
                data: JSON.stringify(result[0]),
                success: function (value) {
                        $('#o_parent_employee').append(value);
                        self.parent = value
                        },
            });
 if we added all classes values in a variable and you can use the value through the controller
Controller:

@http.route('/org_chart', type='http', auth='user', method=['POST'],
                csrf=False)
    def organizational_chart(self, **post):
        parent = post.get('parent')
        data = {'parent': parent}
        context = {'active_model': 'organizational.report',
                   'landscape': 'True'},
        pdf, _ = request.env.ref(
            'module_name.action_report_organizational_chart').with_context(
            landscape=True)._render_qweb_pdf(data=data)
        pdfhttpheaders = [('Content-Type', 'application/pdf'),
                          ('Content-Length', len(pdf))]
        return request.make_response(pdf, headers=pdfhttpheaders)


XML:

<record id="action_report_organizational_chart" model="ir.actions.report">
 
  <field name="name">Organizational chart</field>
<field name="model">organizational.report</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">module_name.organizational_chart_report</field>
<field name="paperformat_id" ref="paper_format_org_chart"/>// you can add the paper format here
</record>

<template id="organizational_chart_report">
    <t t-call="web.html_container">
        <t t-call="web.internal_layout">
            <h2><center>
                <span>Organizational Chart</span>
            </center></h2><br/>
            <br/>
            <center>
                <t t-raw="parent"/>
            </center>
        </t>
    </t>
</template>


if you do not need a controller or js files, you can directly pass the div chat main class through the variable


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 19
3618
1
Nov 24
1014
0
Aug 24
1202
2
Nov 23
2915
5
Aug 23
9235