Odoo Help


Odoo Tree View Each Row Add Button Call Function Return Error

Ashish Singh
on 3/11/15, 9:37 AM 2,857 views

I had Created below tree view and in each row i had added button 

<tree string="Product Lines" editable="bottom">

                                    <field name="sequence" widget="handle"/>
                                    <field name="product_id" on_change="product_id_change(product_id,qty)"/>
                                    <field name="name"/>
                                    <field name="building_method"/>
                                   <field name="qty"/>
                                    <field name="unit_price" />
                                    <field name="sub_total"/>
                    <button string="View Product" icon="gtk-redo" name="view_product_form" type="object"/>

When i click on button it's call view_product_form function 

def view_product_form(self,cr,uid,ids,context=None):
        current_obj = self.browse(cr,uid,ids,context=context)
        product_id = self.pool.get('product.template').browse(cr,uid,current_obj.product_id.product_tmpl_id.id,context=context)
        ir_model_data = self.pool.get('ir.model.data')
        form_res = ir_model_data.get_object_reference(cr, uid, 'product', 'product_template_form_view')
        form_id = form_res and form_res[1] or False

        return {
            'name': _('Products'),
            'view_type': 'form',
            'view_mode': 'from',
            'res_model': 'product.template',
            'res_id': product_id,
            'view_id': False,
            'views': [(form_id, 'form')],
            'context': context,
            #'target': 'current_edit',
            'type': 'ir.actions.act_window',


Above Function return From View To Product Template

But once i click on buttton i get error 

Traceback (most recent call last): File "/opt/odoo/odoo/openerp/http.py", line 500, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/openerp/http.py", line 518, in dispatch return self._json_response(result) File "/opt/odoo/odoo/openerp/http.py", line 489, in _json_response body = simplejson.dumps(response) File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 354, in dumps return _default_encoder.encode(obj) File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 262, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 340, in iterencode return _iterencode(o, 0) File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 239, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: product.template(2,) is not JSON serializable

What i am missing pls help me guys




| 5 3 8
Delhi, India

Nothing to say .... :)

On 3/11/15, 10:16 AM

Change line

   product_id = self.pool.get('product.template').browse(cr,uid,current_obj.product_id.product_tmpl_id.id,context=context


  product_id = current_obj.product_id.product_tmpl_id.id

You are supposed to pass form id which is 2 for the record you posted. but it is being passed as record set which is product.template(2,).



About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/11/15, 9:37 AM
Seen: 2857 times
Last updated: 3/27/15, 6:42 PM