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

I’d like to add custom python function on my report, but I stuck with common known error:

File "D:\Program Files (x86)\Odoo 8.0-20150411\server\.\openerp\tools\safe_eval.py", line 314, in safe_eval File "", line 1, in <module>QWebException: "'NoneType' object is not callable" while evaluating'get_texto1()'

Please I have read all the tutorials but I can not find the trouble, I think my code don't override report_sxw.rml_parse then It can not read the localcontext that I written.

If you have any idea ? please help me

here is it code

my wizard reporte_stock_inv_wz.py

from openerp.osv import osv, fields
class reporte_stock_inv_wz(osv.osv_memory):
    _name = "stock.reporte_stock_inv_wz"
    _description = "Reporte de Inventarios GOC"
    _columns={
        'reporte_nombre':fields.char('Nombre del reporte'),
        'product_ids':fields.many2many('product.product', 'reporte_stock_inv_wz_rel', 'product_id_rep', 'product_id', 'Productos'),
    }

    def get_texto_f(self): return 'Titulo desde funcion'

# function for action button is OK
    def reporte_productos_pdf(self, cr, uid, ids, context=None):
        reporte_data = self.browse(cr, uid, ids, context=context)
        if context is None:
            context = {}
        data = {}
        data['ids'] = context.get('active_ids', [])
        data['model'] = context.get('active_model', 'ir.ui.menu')
        data['form'] = self.read(cr, uid, ids)[0]
        context['titulo'] = "Funciona porfa"
        return self.pool['report'].get_action(cr, uid, [], 'stock.reporte_stock', data=data, context=context)


my report _sxw  reporte_stock.py


from openerp.report import report_sxw
from penerp.osv import osv

class reporte_stock(report_sxw.rml_parse):
    def __init__(self,cr,uid,name,context=None):
        super(reporte_stock, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'texto1':'Titulo desde local context',
            'get_texto1':self._get_texto_1, })

    def _get_texto_1(self):
        return 'Titulo desde funcion texto1'

class report_reporte_stock(osv.AbstractModel):
    _name = 'report.stock.report_reporte_stock'
    _inherit = 'report.abstract_report'
    _template = 'stock.reporte_stock'
    _wrapped_report_class=reporte_stock


my xml   reporte_stock.xml

this code is ok 

<h1><t t-esc="docs._context['titulo']"/></h1>

<h1><t t-esc="docs.get_texto_f()"/></h1>

but when I add the follow code error happen 

<p t-esc="get_texto1()"/>


<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="stock.reporte_stock" name="Reporte de stock con wizard">
            <t t-call="report.html_container">
                <t t-call="report.internal_layout">
                    <div class="page">
                        <h2>REPORTE DE PRUEBA</h2>
                        <p t-esc="get_texto1()"/>
                        <h1><t t-esc="docs._context['titulo']"/></h1>
                        <h1><t t-esc="docs.get_texto_f()"/></h1>
                        <table class="table">
                        <thead>
                            <tr>
                                <th>Prodcuto</th>
                                <th>Descripcion</th>
                                <th>Cantidad</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        </table>
                    </div>
                </t>
            </t>
        </template>
    </data>
</openerp>


thanks so much

 



Avatar
Discard
Author Best Answer

Finally It solved, the problem is in class inherited from AbstractModel

Look at properties _name and _template, underlined parts must be the same, that mean have same name

class report_reporte_stock(osv.AbstractModel):

     _name = 'report.stock.report_reporte_stock'

     _inherit = 'report.abstract_report'

     _template = 'stock.reporte_stock'

     _wrapped_report_class=reporte_stock

I replaced

_template = 'stock.reporte_stock'

with

_template = 'stock.report_reporte_stock'

I hope this comment is useful for someone.

Avatar
Discard