zoukankan      html  css  js  c++  java
  • odoo中的domain的所有操作符

    源码js中有一个映射关系:

    C:Usersdev01gitprojectodoo12addonswebstaticsrcjswidgetsdomain_selector.js

    var operator_mapping = {
        "=": "=",
        "!=": _lt("is not ="),
        ">": ">",
        "<": "<",
        ">=": ">=",
        "<=": "<=",
        "ilike": _lt("contains"),
        "not ilike": _lt("does not contain"),
        "in": _lt("in"),
        "not in": _lt("not in"),
    
        "child_of": _lt("child of"),
        "parent_of": _lt("parent of"),
        "like": "like",
        "not like": "not like",
        "=like": "=like",
        "=ilike": "=ilike",
    
        // custom
        "set": _lt("is set"),
        "not set": _lt("is not set"),
    };



    但是好多操作符还是不能用在xml视图文件中,网上是这么解释的
    We suggest you to use '=' operator instead of ilike. '=' operator works as a =ilike operator.
    because Some operators like "ilike, =ilike, like, =like, not ilike,not like" are not supported in "attrs" parameter.


    The point is domain calculations (attrs is also using domain) are done in JS not the database, so you can not use SQL commands such as 'ilike'. You can see this discussion in my log. 

    But there is a way to add this function to Odoo rather easily with some coding. Edit `view_form.js` ( in openerp/addons/web/static/src/js), find this line:

                case 'not in':
                    if (!_.isArray(val)) val = [val];
                    stack.push(!_(val).contains(field_value));
                    break;

    and add these lines after it:

                case 'like':
                    stack.push(field_value.indexOf(val)>=0);
                    break;
                case 'not like':
                    stack.push(field_value.indexOf(val)<0);
                    break;
                case 'ilike':
                    stack.push(field_value.toUpperCase().indexOf(val.toUpperCase())>=0);
                    break;
                case 'ilike':
                    stack.push(field_value.toUpperCase().indexOf(val.toUpperCase())<0);
                    break; 

    and save it, TADA you can use it now. 

    warning: if you use it with a field which is not string, it will cause an error

    Cheers, 

    Pouya

    更正一下:

    操作符ilike还是可以用在attrs中,之前不能用是因为字段的值为false,因此调用indexOf方法报错:

    以下为调用源代码:

    C:Usersdev01gitprojectodoo12addonswebstaticsrcjscoredomain.js

    switch (this._data[1]) {
    case "=":
    case "==":
    return _.isEqual(fieldValue, this._data[2]);
    case "!=":
    case "<>":
    return !_.isEqual(fieldValue, this._data[2]);
    case "<":
    return (fieldValue < this._data[2]);
    case ">":
    return (fieldValue > this._data[2]);
    case "<=":
    return (fieldValue <= this._data[2]);
    case ">=":
    return (fieldValue >= this._data[2]);
    case "in":
    return _.contains(
    _.isArray(this._data[2]) ? this._data[2] : [this._data[2]],
    fieldValue
    );
    case "not in":
    return !_.contains(
    _.isArray(this._data[2]) ? this._data[2] : [this._data[2]],
    fieldValue
    );
    case "like":
    return (fieldValue.toLowerCase().indexOf(this._data[2].toLowerCase()) >= 0);
    case "ilike":
    return (fieldValue.indexOf(this._data[2]) >= 0);
    default:
    throw new Error(_.str.sprintf(
    "Domain %s uses an unsupported operator",
    this._data
    ));
    }
  • 相关阅读:
    开机启动服务(ftp、apache、mysql)
    ElasticSearch + Canal 开发千万级的实时搜索系统【转】
    filebeat 报错 Unable to create runner due to error: Can only start a prospector when all related states are finished
    linux挂载 mount
    cas单点登录原理
    SpringBoot项目集成cas单点登录
    注解@Slf4j的作用
    Java操作Redis
    CentOS下firewalld添加开放端口
    Prometheus Querying Function rate() vs irate()
  • 原文地址:https://www.cnblogs.com/qianxunman/p/12133069.html
Copyright © 2011-2022 走看看