Pregunta

Followup question from openerp override onchange behavior without affecting base 15244031

The following code does get fired but I get server error 500 when any of the related fields has a value.

When I look at the log, it says JSON serialization issue.

TypeError: browse_record(product.mycount, 1) is not JSON serializable

Please suggest a solution.

class purchase_order_line_custom(osv.osv):
_name = 'purchase.order.line'
_inherit = 'purchase.order.line'

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, context=None):
values = super(purchase_order_line_custom, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order, fiscal_position_id, date_planned,name, price_unit, context=context)
  if product_id:
    product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
    values['value'].update({
                            'qualified_name':product.qualified_name,
                            'product_type' : product.product_type or None,
                            'product_subtype' : product.product_subtype,
                            'count_id':product.count_id or None 
    })
  return values   

  _columns={
      'product_type': fields.related('product_id','product_type',type='selection', string='Product Type', selection=[('X','X'),('Y','Y'),('Z','Z')]),
      'product_subtype': fields.related('product_id','product_subtype',type='char', size=64, string='Sub-Type'),
      'qualified_name': fields.related('product_id','qualified_name',type='char', size=64, string='Qualified Name'),
      'count_id': fields.related('product_id','count_id',type='many2one',relation='product.mycount',string='Count')
      }

purchase_order_line_custom() 
¿Fue útil?

Solución

in the line 'count_id':product.count_id or None, I think count_id is a many2one field in product.you are trying to pass object to the count_id field in product.order.line, you need to pass product.count_id.id to get the id.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top