order' object has no attribute '_line_no' while making custom reports in openerp

384 views Asked by At
def _blank_line(self,nlines):
 res = ""
 for i in range(nlines - self.line_no):
     res = res + '\n'
     return res 
def _line_no(self):
   self.line_no = self.line_no + 1
   return self.line_no

This is my orper.py And now ...In my RML code :

      <para style="terp_default_8">[[ repeatIn(o.order_line,'line') ]][[ line_no() ]][[ line.name or ' ' ]] </para>
    <blockTable colWidths="20.0,100.0,150.0,80.0,50.0,20.0,60.0,50.0" style="Table_Order_Pur_line_Content">
      <tr>
        <para style="terp_default_8"><font color="white">[[ blank_line(10) ]][[ setTag('para','xpre') ]]</font></para>
      <td>

i can not generate report. what is the error.

    3-12-09 17:24:46,257 5716 INFO Test_Dec werkzeug: 127.0.0.1 - - [09/Dec/2013 17:24:46] "POST /web/dataset/call_kw HTTP/1.1" 200 -
2013-12-09 17:24:46,276 5716 INFO Test_Dec werkzeug: 127.0.0.1 - - [09/Dec/2013 17:24:46] "POST /web/dataset/call_kw HTTP/1.1" 200 -
2013-12-09 17:24:47,828 5716 INFO Test_Dec werkzeug: 127.0.0.1 - - [09/Dec/2013 17:24:47] "POST /web/action/load HTTP/1.1" 200 -
2013-12-09 17:24:48,104 5716 ERROR Test_Dec openerp.tools.safe_eval: Cannot eval 'line_no()'
Traceback (most recent call last):
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\tools\safe_eval.py", line 241, in safe_eval
  File "", line 1, in <module>
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\openerp\addons\purchase\report\order.py", line 38, in _line_no
TypeError: range() integer end argument expected, got order.
2013-12-09 17:24:48,104 5716 ERROR Test_Dec openerp.tools.safe_eval: Cannot eval "blank_line(10)]][[ setTag('para','xpre')"
Traceback (most recent call last):
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\tools\safe_eval.py", line 241, in safe_eval
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\tools\safe_eval.py", line 107, in test_expr
  File "<string>", line 1
     blank_line(10)]][[ setTag('para','xpre')
                   ^
 SyntaxError: invalid syntax
2013-12-09 17:24:48,104 5716 WARNING Test_Dec openerp.report.render.rml2pdf.utils: rml_tag: "blank_line(10)]][[ setTag('para','xpre')"
Traceback (most recent call last):
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\report\render\rml2pdf\utils.py", line 84, in _child_get
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\tools\safe_eval.py", line 241, in safe_eval
  File "C:\Program Files\OpenERP 7.0-20131021-123225\Server\server\.\openerp\tools\safe_eval.py", line 107, in test_expr
  File "<string>", line 1
     blank_line(10)]][[ setTag('para','xpre')
                   ^
 SyntaxError: invalid syntax
2

There are 2 answers

1
Andrei Boyanov On

To have access to *line_no()* and *blank_line()* in your RML file you need to declare them in the localcontext dictionary of your parser class. In your __init__() method of your order.py you should have something like

    self.localcontext.update( {
        'line_no': self._line_no,
        'blank_line': self._blank_line,
        ....
    })

Do you have it?

0
user2174132 On

Is this issue resolved or is it still open. I was also facing same issue and found the problem in .xml file

report id="report_appointment_letter" model="hr.contract" name="appointment.report" string="Appointment Letter" rml="addons/hr_contract_report/report/appointment_report.rml"

The name parameter in xml should be same as that in you report parser class:

class appointment_report(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
    if context is None:
        context = {}
    super(appointment_report, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
        'show_date': self._show_date,
        'time': time,

    })
    self.context = context

Hope this will help others if this problem still exists