从另一个字段更改onchange中的many2one字段内容?

时间:2015-05-25 05:51:29

标签: openerp odoo openerp-7 odoo-8

我试图在另一个字段触发onchange方法时更改many2one字段的内容。

继承我的py代码:

class proevent(osv.osv):
_name = 'proevent.events'
_description = 'Events Module'

def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
    res={}
    order_obj = self.pool.get('sale.order')
    order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
    logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
    logging.info(order_ids)
    res['sale_orders_ids'] = order_ids
    logging.info(res)
    return {'value':res}


_columns = {
    'eventdesc': fields.char('Evento', required=True),
    'client_id': fields.many2one('res.partner', 'Cliente', required=True, change_default=True, select=True,track_visibility='always',domain=[('customer','=',True)]),
    'sale_orders_ids': fields.many2one('sale.order','Lista'),
    'eventaddress': fields.char('Direccion de Evento', required=True),
    'description': fields.char('Descripcion del Evento', required=True),
    'datein': fields.date('Fecha de Ingreso a Sistema', required=True, readonly=True),
    'setupdatein': fields.datetime('Inicio de Montaje', required=True),
    'setupdateout': fields.datetime('Fin de Montaje', required=True),
    'eventdatein': fields.datetime('Inicio de Evento', required=True),
    'eventdateout': fields.datetime('Fin de Evento', required=True),
    'eventnotes': fields.char('Notas del Evento', required=True),
    'readonlynote': fields.char('Nota'),
    'partner_rtn': fields.related('partner_id','RTN',type="char",relation="res.partner",string="RTN",store=True,readonly=True),


}
proevent()

当我选择一个被过滤的client_id只显示客户时,触发onchange方法然后选择onchange_client函数。

我的问题是我不能让我的sale_orders_ids many2one字段只显示所选合作伙伴的销售订单ID,它会显示系统的所有销售订单。

如何填充sales_order_ids字段?

1 个答案:

答案 0 :(得分:2)

def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
    res={}
    order_obj = self.pool.get('sale.order')
    order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
    logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
    logging.info(order_ids)
    return {'domain':{'sale_orders_ids':[('id','in',order_ids)]}}

你可以在many2one字段上设置域名。