【发布时间】:2014-05-09 09:42:21
【问题描述】:
我正在尝试从 OpenERP 中另一个 DDL 的值填充我的 DDL(选择)。这是我尝试过的代码。
这是我的视图 XML:
<h1>
<label for="categ1" string="Parent category"/>
<field name="categ1" on_change="Product_Category_OnChange(categ1)" />
</h1>
<newline/>
<h1>
<label for="my_products" string="Products" />
<field name="my_products" />
</h1>
我的_columns 对于这个观点是这样的:
_columns = {
'categ1':fields.many2one('product.category','Parent Category',required=True),
'my_products':fields.many2one('product.product','Products')
}
我的onchange 函数是这样的:
def Product_Category_OnChange(self,cr,uid,ids,categ1):
pro_id={}
cr.execute('select ... where parent_id='+str(categ1))
res = cr.fetchall()
for i in range(len(res)):
pro_id[i]=res[i]
return {'domain':{'my_products': pro_id}}
问题是,我没有得到my_products 的过滤值,而是得到my_products 中的所有值。请让我知道,我做错了什么,或者指出我正确的方向。谢谢
【问题讨论】:
-
您可以在 xml 或 py 中使用域过滤器,为什么您尝试在 on_change 上这样做?
-
我在 Py 文件和 xml 中使用域过滤器进行了尝试,但实际上由于模型中的一些自联接和父子关系,我必须使用查询来执行此操作。这就是我在
on_change方法中这样做的原因。任何建议有什么问题。 -
如果你能详细说明或发布一些链接,以便我有一些想法
-
检查@dhana的答案
标签: python openerp onchange openerp-7