3

我想在.py 的视图或字段定义中给出一个动态域方程。

<field name="product_id" domain="[('name','in',get_names)]"/>

product_id 是一个 many2one 字段。

get_names 是在运行时创建列表的函数。

它显示错误 - “名称'get_names'未定义”

有任何想法吗。

我也尝试过以下方法。

'product_id': fields.many2one('mymodule.relation.model','Title',selection=get_names)

这将显示 mymodule.relation.model 中的所有条目。它唯一要做的就是验证用户选择/提交的值是否属于“get_names”。

4

4 回答 4

2

继承 fields_view_get() 函数并管理域条件。请检查这些帖子

  1. 如何在 OpenERP 上创建动态视图
  2. 如何根据其他字段值更改 OpenERP 选择字段中的选项?
于 2012-11-09T14:14:19.447 回答
2

1-您可以像这样使用函数字段:

def _get_domain(self, cr, uid, ids, field_name, arg, context=None):
    record_id = ids[0] 
    # do some computations....
    return {record_id: YOUR DOMAIN} 

和功能领域:

'domain_field': fields.function(_get_domain, type='char', size=255, method=True, string="Domain"),

并使用 xml 中的字段名称(域属性):

<field name="product_id" domain="domain_field" />

2-您可以使用“fields_view_get”:

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(taskmng_task, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
    doc = etree.XML(res['arch'])
    for node in doc.xpath("//field[@name='project_id']"):
        # do some computations....
        node.set('domain', YOUR DOMAIN)
    res['arch'] = etree.tostring(doc)
    return res
于 2013-06-26T09:00:03.260 回答
0

您不能在域表达式中使用函数或方法,只能使用对象字段。它不是等效的,但最接近的是创建一个函数字段以在域表达式中使用。

于 2012-11-08T21:46:28.507 回答
-3

由于不知道您的确切要求。但可能是这两个中的任何一个都可以帮助您

http://ruchir-shukla.blogspot.in/2010/11/domains-value-depending-on-condition.html

或查看 Account Invoice 产品 onchange 。您可以从 onchange 中返回域。

于 2012-11-08T10:48:40.330 回答