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
    ));
    }
  • 相关阅读:
    Nero8刻录引导系统光盘镜像图文教程
    C#多线程与并行编程方面的电子书,中英文版本
    [转]C#通过委托更新UI(异步加载)
    [PHP] 6种负载均衡算法
    [GIt] 团队工作效率分析工具gitstats
    [Git] git代码统计
    [Git] 写文章 史上最全文献检索、阅读及管理攻略
    [Git] 谷歌的代码管理
    [JQuery] jQuery选择器ID、CLASS、标签获取对象值、属性、设置css样式
    [Mongo] 解决mongoose不支持条件操作符 $gt$gte:$lte$ne $in $all $not
  • 原文地址:https://www.cnblogs.com/qianxunman/p/12133069.html
Copyright © 2011-2022 走看看