【问题标题】:if domain returned from onchange field has no selection values如果从 onchange 字段返回的域没有选择值
【发布时间】:2014-02-04 09:26:16
【问题描述】:

我想将域放在 Sales Person() 上,以便只显示所选销售团队的销售人员。

为此,我在 section_id(sales team) 上创建了 on_change(),并从该方法返回域。虽然当我进入开发者模式时域显示在销售人员(user_id)上,但那里没有显示任何值。

代码如下:

def onchange_section_id(self, cr, uid, ids, section_id, context=None):
    crm_case_section_obj = self.pool.get('crm.case.section')
    member_ids = []
    if section_id:
        member_ids = [member_id.id for member_id in crm_case_section_obj.browse(cr, uid, section_id, context=context).member_ids]
    return {'domain': {'user_id': [('user_id', 'in', member_ids)]}}

我错过了什么吗?

提前感谢。

【问题讨论】:

  • 以另一种方式,我们可以通过在您的模块中获取核心模块和宫殿的整个标签并提供父对象来将域放在 .xml 中。如果你想展示域宫比我会给出答案。因为这个问题我已经面对了。谢谢

标签: openerp onchange


【解决方案1】:

试试这个 pooja,希望这能解决你最近遇到的问题

def onchange_section_id(self, cr, uid, ids, section_id, context=None):
    crm_case_section_obj = self.pool.get('crm.case.section')
    member_ids = []
    if section_id:
        member_ids = [member_id.id for member_id in crm_case_section_obj.browse(cr, uid, section_id, context=context).member_ids]
    return {'domain': {'user_id': [('id', 'in', member_ids)]}, 'value': {'user_id': False}}

【讨论】:

    【解决方案2】:

    我认为你在这里犯了一个小错误。

    以这种方式使用域:{'domain': {'user_id': [('id', 'in', member_ids)]}}

    def onchange_section_id(self, cr, uid, ids, section_id, context=None):
        crm_case_section_obj = self.pool.get('crm.case.section')
        member_ids = []
        if section_id:
            member_ids = [member_id.id for member_id in crm_case_section_obj.browse(cr, uid, section_id, context=context).member_ids]
        return {'domain': {'user_id': [('id', 'in', member_ids)]}}
    

    【讨论】:

    • 没用。出现错误。 DataError:整数的输入语法无效:“Demo User”第 1 行:..._id"."name" IS NULL)) AND ("res_users"."id" in ('Demo User...
    • 给出你的全部回溯,你是openerp的学习者吗,你的错误说明就是这样
    • 糟糕,这是我的错误。好吧,我发现了。是的,它奏效了。给朋友带来不便,请见谅。而且您的代码使用起来似乎有点不友好。希望您不介意我是否会编辑您的答案,毕竟这是为了提供更好的解决方案。
    • 嗨,亲爱的,这不是我的代码,它是 pooja 的代码,我只是纠正了错误的事情,我不是来指导人们进行 pep8 规则或更正代码
    • 我知道。甚至没有人在这里指导 pep8 规则。我不是在谈论那种变化。
    【解决方案3】:

    这里的答案对我不起作用,但 user1576199 的评论对我有用。

    def onchange_section_id(self, cr, uid, ids, section_id, context=None):
        crm_case_section_obj = self.pool.get('crm.case.section')
        member_ids = []
        if section_id:
            member_ids = [member_id.id for member_id in crm_case_section_obj.browse(cr, uid, section_id, context=context).member_ids]
        return {'domain': {'user_id': str([('id', 'in', member_ids)]) }}
    

    这里的技巧是将实际域作为字符串传递,因为这就是 Web 客户端期望域值的方式。所以使用 str( [('id', in, member_ids)] )

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      相关资源
      最近更新 更多