繁体   English   中英

在openerp中调用其他字段的onchange函数时更改选择字段值

[英]Change the selection field value on calling onchange function of other field in openerp

我一直在研究OpenERP模块。 场景是我有一个包含某些资产类别的选择字段。 我还有另一个领域,它与onchange函数相关联。 现在我想要的是当我的onchange函数被调用时,选择字段值使用其下拉值之一动态设置。 选择字段是“ asset_type”,另一个字段是“ categ_temp2”。 我尝试了以下技术,但没有奏效。

<field name="categ_temp2" domain="[('parent_id', '!=', False)]" on_change="mmProduct_Category_OnChange(categ_temp2,asset_type)"/>

def mmProduct_Category_OnChange(self,cr,uid,ids,categ_temp2,asset_type):
    for id in ids: 
             emp = self.pool.get('product.product')
             emp.write(cr,uid,ids,{'asset_type', '=', 'phones'})

请指出我的错误或指导我解决这个问题。 谢谢

我在Python代码中使用以下语法解决了该问题:

  def myProduct_Category_OnChange(self,cr,uid,ids,categ_temps):
        pro_id=[]
        if (str(categ_temps)=='3'):
            return {'value':{'asset_type': 'phones'}}  

“ 3”是在第一个字段上设置的类别的ID(即categ_temps)。通过这样做,当“ catge_temps”设置为id:3时,即可动态选择asset_type中的tha值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM