This question has been flagged
1 Reply
6845 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"/>
</tree>

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

Avatar
Discard
Best Answer

Change line

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

to

  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,).

 

 

Avatar
Discard