From d90dbe6d0a442e395a824b4ecc66cae1cd85e316 Mon Sep 17 00:00:00 2001 From: "laurent.corron" Date: Mon, 11 Nov 2019 20:24:52 +0100 Subject: [PATCH] [MIG] web_domain_field: Migration to 13.0 --- web_domain_field/__manifest__.py | 9 +- web_domain_field/i18n/web_domain_field.pot | 9 +- web_domain_field/static/src/js/pyeval.js | 415 ++++++++++---------- web_domain_field/views/web_domain_field.xml | 2 +- 4 files changed, 206 insertions(+), 229 deletions(-) diff --git a/web_domain_field/__manifest__.py b/web_domain_field/__manifest__.py index 4391a4595..0c503be54 100644 --- a/web_domain_field/__manifest__.py +++ b/web_domain_field/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -6,11 +5,11 @@ "name": "Web Domain Field", "summary": """ Use computed field as domain""", - "version": "10.0.1.0.0", + "version": "13.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV,Odoo Community Association (OCA)", - "website": "https://acsone.eu/", + "website": "https://github.com/OCA/web", "depends": ["web"], - "data": ["views/web_domain_field.xml",], - "demo": [], + "data": ["views/web_domain_field.xml"], + "installable": True, } diff --git a/web_domain_field/i18n/web_domain_field.pot b/web_domain_field/i18n/web_domain_field.pot index 04177b360..04afd2b4f 100644 --- a/web_domain_field/i18n/web_domain_field.pot +++ b/web_domain_field/i18n/web_domain_field.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_domain_field +# * web_domain_field # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 10.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -15,8 +15,7 @@ msgstr "" #. module: web_domain_field #. openerp-web -#: code:addons/web_domain_field/static/src/js/pyeval.js:160 +#: code:addons/web_domain_field/static/src/js/pyeval.js:0 #, python-format msgid "Unknown nonliteral type " msgstr "" - diff --git a/web_domain_field/static/src/js/pyeval.js b/web_domain_field/static/src/js/pyeval.js index f4b75e579..6f2b9f61b 100644 --- a/web_domain_field/static/src/js/pyeval.js +++ b/web_domain_field/static/src/js/pyeval.js @@ -1,233 +1,212 @@ odoo.define('web.domain_field', function (require) { -"use strict"; + "use strict"; -var pyeval = require('web.pyeval'); -var session = require('web.session'); + var py_utils = require('web.py_utils'); + var session = require('web.session'); -var original_pyeval = pyeval.eval; -var original_ensure_evaluated = pyeval.ensure_evaluated; -var py = window.py; + var original_pyeval = py_utils.eval; + var py = window.py; -/** copied from pyeval and not modified but required since not publicly -exposed by web.pyeval**/ + /** Copied from py_utils and not modified but required since not publicly + exposed by web.py_utils**/ -// recursively wraps JS objects passed into the context to attributedicts -// which jsonify back to JS objects -function wrap(value) { - if (value === null) { return py.None; } + // recursively wraps JS objects passed into the context to attributedicts + // which jsonify back to JS objects + function wrap(value) { + if (value === null) { return py.None; } - switch (typeof value) { - case 'undefined': throw new Error("No conversion for undefined"); - case 'boolean': return py.bool.fromJSON(value); - case 'number': return py.float.fromJSON(value); - case 'string': return py.str.fromJSON(value); + switch (typeof value) { + case 'undefined': throw new Error("No conversion for undefined"); + case 'boolean': return py.bool.fromJSON(value); + case 'number': return py.float.fromJSON(value); + case 'string': return py.str.fromJSON(value); + } + + switch(value.constructor) { + case Object: return wrapping_dict.fromJSON(value); + case Array: return wrapping_list.fromJSON(value); + } + + throw new Error("ValueError: unable to wrap " + value); } - switch(value.constructor) { - case Object: return wrapping_dict.fromJSON(value); - case Array: return wrapping_list.fromJSON(value); - } + var wrapping_dict = py.type('wrapping_dict', null, { + __init__: function () { + this._store = {}; + }, + __getitem__: function (key) { + var k = key.toJSON(); + if (!(k in this._store)) { + throw new Error("KeyError: '" + k + "'"); + } + return wrap(this._store[k]); + }, + __getattr__: function (key) { + return this.__getitem__(py.str.fromJSON(key)); + }, + __len__: function () { + return Object.keys(this._store).length; + }, + __nonzero__: function () { + return py.PY_size(this) > 0 ? py.True : py.False; + }, + get: function () { + var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]); - throw new Error("ValueError: unable to wrap " + value); -} - -var wrapping_dict = py.type('wrapping_dict', null, { - __init__: function () { - this._store = {}; - }, - __getitem__: function (key) { - var k = key.toJSON(); - if (!(k in this._store)) { - throw new Error("KeyError: '" + k + "'"); - } - return wrap(this._store[k]); - }, - __getattr__: function (key) { - return this.__getitem__(py.str.fromJSON(key)); - }, - __len__: function () { - return Object.keys(this._store).length - }, - __nonzero__: function () { - return py.PY_size(this) > 0 ? py.True : py.False; - }, - get: function () { - var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]); - - if (!(args.k.toJSON() in this._store)) { return args.d; } - return this.__getitem__(args.k); - }, - fromJSON: function (d) { - var instance = py.PY_call(wrapping_dict); - instance._store = d; - return instance; - }, - toJSON: function () { - return this._store; - }, -}); - -var wrapping_list = py.type('wrapping_list', null, { - __init__: function () { - this._store = []; - }, - __getitem__: function (index) { - return wrap(this._store[index.toJSON()]); - }, - __len__: function () { - return this._store.length; - }, - __nonzero__: function () { - return py.PY_size(this) > 0 ? py.True : py.False; - }, - fromJSON: function (ar) { - var instance = py.PY_call(wrapping_list); - instance._store = ar; - return instance; - }, - toJSON: function () { - return this._store; - }, -}); - -function wrap_context (context) { - for (var k in context) { - if (!context.hasOwnProperty(k)) { continue; } - var val = context[k]; - - if (val === null) { continue; } - if (val.constructor === Array) { - context[k] = wrapping_list.fromJSON(val); - } else if (val.constructor === Object - && !py.PY_isInstance(val, py.object)) { - context[k] = wrapping_dict.fromJSON(val); - } - } - return context; -} - -function ensure_evaluated (args, kwargs) { - for (var i=0; i 0 ? py.True : py.False; + }, + fromJSON: function (ar) { + var instance = py.PY_call(wrapping_list); + instance._store = ar; + return instance; + }, + toJSON: function () { + return this._store; + }, + }); -// override sync_eval in order to call our specialized implementation of -// eval_domains -function sync_eval_domains_and_contexts (source) { - var contexts = ([session.user_context] || []).concat(source.contexts); - // see Session.eval_context in Python - return { - context: domain_field_pyeval('contexts', contexts), - domain: domain_field_pyeval('domains', source.domains), - group_by: domain_field_pyeval('groupbys', source.group_by_seq || []) - }; -} + function wrap_context(context) { + for (var k in context) { + if (!context.hasOwnProperty(k)) { continue; } + var val = context[k]; + // Don't add a test case like ``val === undefined`` + // this is intended to prevent letting crap pass + // on the context without even knowing it. + // If you face an issue from here, try to sanitize + // the context upstream instead + if (val === null) { continue; } + if (val.constructor === Array) { + context[k] = wrapping_list.fromJSON(val); + } else if (val.constructor === Object + && !py.PY_isInstance(val, py.object)) { + context[k] = wrapping_dict.fromJSON(val); + } + } + return context; + } -pyeval.eval = domain_field_pyeval; -pyeval.ensure_evaluated = ensure_evaluated; -pyeval.sync_eval_domains_and_contexts = sync_eval_domains_and_contexts; + function ensure_evaluated(args, kwargs) { + for (var i=0; i 0 && + domains[0].length === 1 && + (domains[0][0] === "|" || domains[0][0] === "!") + ); + _(domains).each(function (domain) { + if (_.isString(domain)) { + // Modified part or the original method + if (domain in evaluation_context) { + result_domain.push.apply( + result_domain, $.parseJSON(evaluation_context[domain])); + return; + } + // End of modifications + + // wrap raw strings in domain + domain = { __ref: 'domain', __debug: domain }; + } + var domain_array_to_combine; + switch(domain.__ref) { + case 'domain': + evaluation_context.context = evaluation_context; + domain_array_to_combine = py.eval(domain.__debug, wrap_context(evaluation_context)); + break; + default: + domain_array_to_combine = domain; + } + if (need_normalization) { + domain_array_to_combine = get_normalized_domain(domain_array_to_combine); + } + result_domain.push.apply(result_domain, domain_array_to_combine); + }); + return result_domain; + } + + + // Override pyeval in order to call our specialized implementation of + // eval_domains + function domain_field_pyeval (type, object, context, options) { + switch (type) { + case 'domain': + case 'domains': + if (type === 'domain') { + object = [object]; + } + return eval_domains(object, context); + default: + return original_pyeval(type, object, context, options); + } + } + + function eval_domains_and_contexts(source) { + // see Session.eval_context in Python + return { + context: domain_field_pyeval('contexts', source.contexts || [], source.eval_context), + domain: domain_field_pyeval('domains', source.domains, source.eval_context), + group_by: domain_field_pyeval('groupbys', source.group_by_seq || [], source.eval_context), + }; + } + + + py_utils.eval = domain_field_pyeval; + py_utils.ensure_evaluated = ensure_evaluated; + py_utils.eval_domains_and_contexts = eval_domains_and_contexts; + +}); diff --git a/web_domain_field/views/web_domain_field.xml b/web_domain_field/views/web_domain_field.xml index 537d2f874..4d746a551 100644 --- a/web_domain_field/views/web_domain_field.xml +++ b/web_domain_field/views/web_domain_field.xml @@ -5,4 +5,4 @@