Odoo Help

Welcome!

This community 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.

0

How to use a custom report function ?

By
PY
on 11/5/14, 4:27 AM 1,080 views

Hi !

I have a custom function in a report parser :

import time
from openerp.report import report_sxw


class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
        })
    def cheque_no(self, voucher):
        try:
            cheque_no = voucher.cheque_number
            if not cheque_no:
                # no value in field
                return ''
            # value in field
            return cheque_no
        except AttributeError:
            # field not defined
            return False

report_sxw.report_sxw(
    'report.custom.account.invoice',
    'account.invoice',
    'account_payment_method/report/account_print_invoice.rml',
    parser=account_invoice
)

Now, I want to use it in my RML report :

    <blockTable colWidths="150.0,70.0,70.0,70.0,170.0" style="Table_Payment_ids_header">
      <tr>
        <td>
          <para style="terp_tblheader_Details"><b>Payment method [[ o.voucher_ids==[] and removeParentNode('blockTable') ]]</b></para>
        </td>
        <td>
          <para style="terp_tblheader_Details_Centre"><b>Date </b></para>
        </td>
        <td>
          <para style="terp_tblheader_Details_Right"><b>Amount </b></para>
        </td>
        <td>
          <para style="terp_tblheader_Details_Right"><b>Cheque No. [[ cheque_no(o.voucher_ids[0])==False and removeParentNode('td') ]] </b></para>
        </td>
        <td>
          <para style="terp_default_8">
            <font color="white"> </font>
          </para>
        </td>
      </tr>
    </blockTable>
    <section>
      <para style="terp_default_2">[[ repeatIn(o.voucher_ids,'v') ]]</para>
      <blockTable colWidths="150.0,70.0,70.0,70.0,170.0" style="Table_Payment_ids_content">
        <tr>
          <td>
            <para style="terp_default_8">[[ v.journal_id.name ]]</para>
          </td>
          <td>
            <para style="terp_default_Centre_8">[[ v.move_id.date ]]</para>
          </td>
          <td>
            <para style="terp_default_Right_8">[[ formatLang(v.amount, digits=get_digits(dp='Account'), currency_obj=o.currency_id) ]]</para>
          </td>
          <td>
            <para style="terp_default_Right_8">[[ cheque_no(v) or cheque_no(v)==False and removeParentNode('td') ]]</para>
          </td>
          <td>
            <para style="terp_default_8">
              <font color="white"> </font>
            </para>
          </td>
        </tr>
      </blockTable>
    </section>

But the server returns me this error :

2014-11-05 09:02:34,429 4023 ERROR other openerp.tools.safe_eval: Cannot eval " cheque_no(o.voucher_ids[0])==False and removeParentNode('td') "
Traceback (most recent call last):
  File "/home/openerp/server/openerp/tools/safe_eval.py", line 285, in safe_eval
    return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
  File "", line 1, in <module>
NameError: name 'cheque_no' is not defined

Can someone help me solve this ?

 

2
Guillaume Seran
On 11/5/14, 4:42 AM

hi,

self.localcontext.update({
       'time': time,
       'cheque_no' : self.cheque_no,
})

Thanks !

PY
on 11/5/14, 4:46 AM

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/5/14, 4:27 AM
Seen: 1080 times
Last updated: 3/16/15, 8:10 AM