This question has been flagged
2 Replies
6507 Views

I has been following the different posts in the forum to write a report, passing the variables. Like the comment of Niyas here
https://www.odoo.com/es_ES/forum/ayuda-1/question/how-to-define-and-use-a-report-parser-in-odoo-10-124153

And i did the exact same code, the only variable that i can read into the report is docs, if i add another variable like data, i did not see it, even if is a string, just docs, doc_ids, doc_model.

@api.model

    def render_html(self, docids, data=None):

        docs = self.env['account.move'].browse(docids)

        docargs = {

            'doc_ids': self.ids,

            'doc_model':'account.move',

            'docs': docs,

            'data': 'data'

        }

        return self.env['report'].render('module.report', docargs)


and the <p t-esc="data"/>

there is no error, just there is no variable in the debugger, locals(), 

Any ideas?

Avatar
Discard
Author Best Answer

Yes, that is exactly what i want o achieve. I can see that you are using a private method in the class to call the information that you want to show, in the line of get_partner_lines inside docargs.

I did try to pass in that line, a string, a list, a vector, but nothing shows. I did not try to use the private function, i guess that is my next approach.

Thanks,

Avatar
Discard
Best Answer

Hi,
can you try same as:
please see bold text example.

    @api.model

    def render_html(self, docids, data=None):

        if not data.get('form') or not self.env.context.get('active_model') or not self.env.context.get('active_id'):                        raise UserError(_("Form content is missing, this report cannot be printed."))       

        total = []       

        model = self.env.context.get('active_model')

        docs = self.env[model].browse(self.env.context.get('active_id'))

        target_move = data['form'].get('target_move', 'all')

        date_from = data['form'].get('date_from', time.strftime('%Y-%m-%d'))

        if data['form']['result_selection'] == 'customer':

            account_type = ['receivable']

        elif data['form']['result_selection'] == 'supplier':

            account_type = ['payable']

        else:

            account_type = ['payable', 'receivable']

        movelines, total, dummy = self._get_partner_move_lines(account_type, date_from, target_move, data['form']['period_length'])

        docargs = {

            'doc_ids': self.ids,

            'doc_model': model,

            'data': data['form'],

            'docs': docs,

            'time': time,

            'get_partner_lines': movelines,

            'get_direction': total,

        }

        return self.env['report'].render('account.report_agedpartnerbalance', docargs)


Add in Qweb report like:

<tr t-foreach="get_partner_lines" t-as="partner">

    <td><span t-esc="partner['name']"/></td>

</tr>

Thank you.

Avatar
Discard