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
    ));
    }
  • 相关阅读:
    如何计算两个日期之间相差天数
    解决并发问题的小技巧
    Linq实现下拉框绑定
    No DataType in DataTemplate in Windows Phone(二)
    使用TOAD操作oracle初步
    使用log4net记录server Log
    尘世一场烟火
    No DataType in DataTemplate in Windows Phone(—)
    MVC设置初始页时发生的无法找到资源的简单错误
    oracle 使用in的灵异事件
  • 原文地址:https://www.cnblogs.com/qianxunman/p/12133069.html
Copyright © 2011-2022 走看看