From 6966470f9da94cb5e839a8d1ef1fd9ce8ad1c686 Mon Sep 17 00:00:00 2001 From: Jonathan Nemry Date: Fri, 11 Apr 2014 14:11:45 +0200 Subject: [PATCH 1/9] [ADD] web_readonly_bypass: allow to save an onchange modifications on readonly fields --- web_readonly_bypass/__init__.py | 28 +++++ web_readonly_bypass/__openerp__.py | 61 ++++++++++ .../static/src/js/readonly_bypass.js | 109 ++++++++++++++++++ web_readonly_bypass/views/readonly_bypass.xml | 12 ++ 4 files changed, 210 insertions(+) create mode 100644 web_readonly_bypass/__init__.py create mode 100644 web_readonly_bypass/__openerp__.py create mode 100644 web_readonly_bypass/static/src/js/readonly_bypass.js create mode 100644 web_readonly_bypass/views/readonly_bypass.xml diff --git a/web_readonly_bypass/__init__.py b/web_readonly_bypass/__init__.py new file mode 100644 index 00000000..5fa4a2b1 --- /dev/null +++ b/web_readonly_bypass/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Nemry Jonathan & Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py new file mode 100644 index 00000000..7f6410e1 --- /dev/null +++ b/web_readonly_bypass/__openerp__.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Nemry Jonathan & Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Read Only ByPass', + 'version': '1.0', + "author": "ACSONE SA/NV", + "maintainer": "ACSONE SA/NV", + "website": "http://www.acsone.eu", + 'category': 'Technical Settings', + 'depends': [ + 'base', + 'web', + ], + 'description': """ +Read Only ByPass +================ +This Module provides a solution to the problem of the interaction between +'readonly' attribute and 'on_change' attribute when used together + +Behavior: add `readonly_fields` changed by `on_change` into the fields passing +into an update or create. If `filter_out_readonly` is into the context and set +True then apply native behavior. + """, + 'images': [], + 'data': [ + 'views/readonly_bypass.xml', + ], + 'qweb': [ + ], + 'css': [], + 'demo': [], + 'test': [], + 'installable': True, + 'auto_install': False, +} diff --git a/web_readonly_bypass/static/src/js/readonly_bypass.js b/web_readonly_bypass/static/src/js/readonly_bypass.js new file mode 100644 index 00000000..d8581f3e --- /dev/null +++ b/web_readonly_bypass/static/src/js/readonly_bypass.js @@ -0,0 +1,109 @@ +/* + * Allow to bypass readonly fi the value is changed + */ + +openerp.readonly_bypass = function(instance) { + + var QWeb = instance.web.qweb, _t = instance.web._t; + /** + * ignore readonly: place options['readonly_fields'] into the data + * if nothing is specified into the context + * + * create mode: remove read-only keys having a 'false' value + * + * @param boolean mode: True case of create, false case of write + * @param {Object} context->filter_out_readonly + * @param {Object} data field values to possibly be updated + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields to merge into the data object + */ + function ignore_readonly(data, options, mode, context){ + if (options){ + if (!('filter_out_readonly' in context && context['filter_out_readonly'] == true + && 'readonly_fields' in options && options['readonly_fields'])) { + if(mode){ + $.each( options.readonly_fields, function( key, value ) { + if(value==false){ + delete(options.readonly_fields[key]); + } + }); + } + data = $.extend(data,options['readonly_fields']) + } + } + }; + + instance.web.BufferedDataSet.include({ + + init : function() { + this._super.apply(this, arguments); + }, + /** + * Creates Overriding + * + * @param {Object} data field values to set on the new record + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields that were updated by + * on_changes. Only used by the BufferedDataSet to make the o2m work correctly. + * @returns super {$.Deferred} + */ + create : function(data, options) { + var self = this; + ignore_readonly(data, options, true, self.context); + return self._super(data,options); + }, + /** + * Creates Overriding + * + * @param {Object} data field values to set on the new record + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields that were updated by + * on_changes. Only used by the BufferedDataSet to make the o2m work correctly. + * @returns super {$.Deferred} + */ + write : function(id, data, options) { + var self = this; + ignore_readonly(data, options, false, self.context); + return self._super(id,data,options); + }, + + }); + + instance.web.DataSet.include({ + /* + BufferedDataSet: case of 'add an item' into a form view + */ + init : function() { + this._super.apply(this, arguments); + }, + /** + * Creates Overriding + * + * @param {Object} data field values to set on the new record + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields that were updated by + * on_changes. Only used by the BufferedDataSet to make the o2m work correctly. + * @returns super {$.Deferred} + */ + create : function(data, options) { + var self = this; + ignore_readonly(data, options, true, self.context); + return self._super(data,options); + }, + /** + * Creates Overriding + * + * @param {Object} data field values to set on the new record + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields that were updated by + * on_changes. Only used by the BufferedDataSet to make the o2m work correctly. + * @returns super {$.Deferred} + */ + write : function(id, data, options) { + var self = this; + ignore_readonly(data, options, false, self.context); + return self._super(id,data,options); + }, + + }); +}; diff --git a/web_readonly_bypass/views/readonly_bypass.xml b/web_readonly_bypass/views/readonly_bypass.xml new file mode 100644 index 00000000..2bad7ace --- /dev/null +++ b/web_readonly_bypass/views/readonly_bypass.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file From 991c74746c04b51a75666a6fc16483def3771e6c Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 3 Jul 2015 01:26:28 +0200 Subject: [PATCH 2/9] port web_readonly_bypass on v7 --- web_readonly_bypass/__openerp__.py | 98 ++++++++++++++----- .../static/src/js/readonly_bypass.js | 7 +- web_readonly_bypass/views/readonly_bypass.xml | 12 --- 3 files changed, 80 insertions(+), 37 deletions(-) delete mode 100644 web_readonly_bypass/views/readonly_bypass.xml diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py index 7f6410e1..cb2fdee9 100644 --- a/web_readonly_bypass/__openerp__.py +++ b/web_readonly_bypass/__openerp__.py @@ -3,14 +3,6 @@ # # Authors: Nemry Jonathan & Laetitia Gangloff # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -29,8 +21,8 @@ { 'name': 'Read Only ByPass', 'version': '1.0', - "author": "ACSONE SA/NV", - "maintainer": "ACSONE SA/NV", + "author": "ACSONE SA/NV, Anybox", + "maintainer": "ACSONE SA/NV, Odoo Community Association (OCA)", "website": "http://www.acsone.eu", 'category': 'Technical Settings', 'depends': [ @@ -38,24 +30,86 @@ 'web', ], 'description': """ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + Read Only ByPass ================ -This Module provides a solution to the problem of the interaction between -'readonly' attribute and 'on_change' attribute when used together -Behavior: add `readonly_fields` changed by `on_change` into the fields passing -into an update or create. If `filter_out_readonly` is into the context and set +This module provides a solution to the problem of the interaction between +'readonly' attribute and 'on_change' attribute when used together. It allows +saving onchange modifications to readonly fields. + +Behavior: add readonly fields changed by `on_change` methods to the values +passed to write or create. If `filter_out_readonly` is in the context and True then apply native behavior. + +Installation +============ + +There are no specific installation instructions for this module. + +Configuration +============= + +There is nothing to configure. + +Usage +===== + +This module changes the default behaviour of Odoo by propagating +on_change modifications to readonly fields to the backend create and write +methods. + +To restore the standard behaviour, set `filter_out_readonly` in the context. + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +None + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Jonathan Nemry +* Laetitia Gangloff +* Pierre Verkest + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. """, - 'images': [], - 'data': [ - 'views/readonly_bypass.xml', - ], - 'qweb': [ + 'js': [ + 'static/src/js/readonly_bypass.js', ], - 'css': [], - 'demo': [], - 'test': [], 'installable': True, 'auto_install': False, + 'application': False, } diff --git a/web_readonly_bypass/static/src/js/readonly_bypass.js b/web_readonly_bypass/static/src/js/readonly_bypass.js index d8581f3e..d497826a 100644 --- a/web_readonly_bypass/static/src/js/readonly_bypass.js +++ b/web_readonly_bypass/static/src/js/readonly_bypass.js @@ -2,7 +2,7 @@ * Allow to bypass readonly fi the value is changed */ -openerp.readonly_bypass = function(instance) { +openerp.web_readonly_bypass = function(instance) { var QWeb = instance.web.qweb, _t = instance.web._t; /** @@ -19,8 +19,9 @@ openerp.readonly_bypass = function(instance) { */ function ignore_readonly(data, options, mode, context){ if (options){ - if (!('filter_out_readonly' in context && context['filter_out_readonly'] == true - && 'readonly_fields' in options && options['readonly_fields'])) { + if ('readonly_fields' in options && options['readonly_fields'] && + !('filter_out_readonly' in context && + context['filter_out_readonly'] == true)) { if(mode){ $.each( options.readonly_fields, function( key, value ) { if(value==false){ diff --git a/web_readonly_bypass/views/readonly_bypass.xml b/web_readonly_bypass/views/readonly_bypass.xml deleted file mode 100644 index 2bad7ace..00000000 --- a/web_readonly_bypass/views/readonly_bypass.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file From 5eb3f759d073f205f1126dca3cff11d7326112a9 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 3 Jul 2015 09:48:35 +0200 Subject: [PATCH 3/9] Add README.rst, fix formating --- web_readonly_bypass/README.rst | 75 ++++++++++++++++++++++++++++++ web_readonly_bypass/__openerp__.py | 6 ++- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 web_readonly_bypass/README.rst diff --git a/web_readonly_bypass/README.rst b/web_readonly_bypass/README.rst new file mode 100644 index 00000000..bf9c034f --- /dev/null +++ b/web_readonly_bypass/README.rst @@ -0,0 +1,75 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Read Only ByPass +================ + +This module provides a solution to the problem of the interaction between +'readonly' attribute and 'on_change' attribute when used together. It allows +saving onchange modifications to readonly fields. + +Behavior: add readonly fields changed by `on_change` methods to the values +passed to write or create. If `filter_out_readonly` is in the context and +True then apply native behavior. + +Installation +============ + +There are no specific installation instructions for this module. + +Configuration +============= + +There is nothing to configure. + +Usage +===== + +This module changes the default behaviour of Odoo by propagating +on_change modifications to readonly fields to the backend create and write +methods. + +To restore the standard behaviour, set `filter_out_readonly` in the context. + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +None + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Jonathan Nemry +* Laetitia Gangloff +* Pierre Verkest + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. \ No newline at end of file diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py index cb2fdee9..debb862c 100644 --- a/web_readonly_bypass/__openerp__.py +++ b/web_readonly_bypass/__openerp__.py @@ -77,8 +77,10 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +If you spotted it first, help us smashing it by providing a detailed and +welcomed feedback `here `_. Credits From 790a8536b93585dca141999bfd3766d63cce6e79 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Tue, 14 Jul 2015 13:56:09 +0200 Subject: [PATCH 4/9] by pass readonly fields only if context is set with readonly_by_pass. This context can either be a bool or field name array --- web_readonly_bypass/__openerp__.py | 6 + .../static/src/js/readonly_bypass.js | 87 ++++++--- .../static/test/web_readonly_bypass.js | 168 ++++++++++++++++++ 3 files changed, 235 insertions(+), 26 deletions(-) create mode 100644 web_readonly_bypass/static/test/web_readonly_bypass.js diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py index debb862c..c07d2006 100644 --- a/web_readonly_bypass/__openerp__.py +++ b/web_readonly_bypass/__openerp__.py @@ -108,9 +108,15 @@ promote its widespread use. To contribute to this module, please visit http://odoo-community.org. """, + "depends": [ + 'web', + ], 'js': [ 'static/src/js/readonly_bypass.js', ], + 'test': [ + 'static/test/web_readonly_bypass.js', + ], 'installable': True, 'auto_install': False, 'application': False, diff --git a/web_readonly_bypass/static/src/js/readonly_bypass.js b/web_readonly_bypass/static/src/js/readonly_bypass.js index d497826a..aa40a0d3 100644 --- a/web_readonly_bypass/static/src/js/readonly_bypass.js +++ b/web_readonly_bypass/static/src/js/readonly_bypass.js @@ -5,35 +5,70 @@ openerp.web_readonly_bypass = function(instance) { var QWeb = instance.web.qweb, _t = instance.web._t; - /** - * ignore readonly: place options['readonly_fields'] into the data - * if nothing is specified into the context - * - * create mode: remove read-only keys having a 'false' value - * - * @param boolean mode: True case of create, false case of write - * @param {Object} context->filter_out_readonly - * @param {Object} data field values to possibly be updated - * @param {Object} options Dictionary that can contain the following keys: - * - readonly_fields: Values from readonly fields to merge into the data object - */ - function ignore_readonly(data, options, mode, context){ - if (options){ - if ('readonly_fields' in options && options['readonly_fields'] && - !('filter_out_readonly' in context && - context['filter_out_readonly'] == true)) { - if(mode){ + var instance = instance; + + instance.web_readonly_bypass = { + /** + * ignore readonly: place options['readonly_fields'] into the data + * if nothing is specified into the context + * + * create mode: remove read-only keys having a 'false' value + * + * @param {Object} data field values to possibly be updated + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: Values from readonly fields to merge into the data object + * @param boolean mode: True case of create, false case of write + * @param {Object} context->readonly_by_pass + */ + ignore_readonly: function(data, options, mode, context){ + console.log(options ); + console.log(context ); + var readonly_by_pass_fields = this.retrieve_readonly_by_pass_fields( + options, context); + console.log(readonly_by_pass_fields ); + if(mode){ + $.each( readonly_by_pass_fields, function( key, value ) { + if(value==false){ + delete(readonly_by_pass_fields[key]); + } + }); + } + data = $.extend(data,readonly_by_pass_fields); + console.log(data ); + }, + + /** + * retrieve_readonly_by_pass_fields: retrieve readonly fields to save + * according context. + * + * @param {Object} options Dictionary that can contain the following keys: + * - readonly_fields: all values from readonly fields + * @param {Object} context->readonly_by_pass: Can be true if all + * all readonly fields should be saved or an array of field name to + * save ie: ['readonly_field_1', 'readonly_field_2'] + * @returns {Object}: readonly key/value fields to save according context + */ + retrieve_readonly_by_pass_fields: function(options, context){ + var readonly_by_pass_fields = {}; + if (options && 'readonly_fields' in options && + options['readonly_fields'] && context && + 'readonly_by_pass' in context && context['readonly_by_pass']){ + if (_.isArray(context['readonly_by_pass'])){ $.each( options.readonly_fields, function( key, value ) { - if(value==false){ - delete(options.readonly_fields[key]); + if(_.contains(context['readonly_by_pass'], key)){ + readonly_by_pass_fields[key] = value; } }); + }else{ + readonly_by_pass_fields = options.readonly_fields; } - data = $.extend(data,options['readonly_fields']) } - } + return readonly_by_pass_fields; + }, }; + readonly_bypass = instance.web_readonly_bypass; + instance.web.BufferedDataSet.include({ init : function() { @@ -50,7 +85,7 @@ openerp.web_readonly_bypass = function(instance) { */ create : function(data, options) { var self = this; - ignore_readonly(data, options, true, self.context); + readonly_bypass.ignore_readonly(data, options, true, self.context); return self._super(data,options); }, /** @@ -64,7 +99,7 @@ openerp.web_readonly_bypass = function(instance) { */ write : function(id, data, options) { var self = this; - ignore_readonly(data, options, false, self.context); + readonly_bypass.ignore_readonly(data, options, false, self.context); return self._super(id,data,options); }, @@ -88,7 +123,7 @@ openerp.web_readonly_bypass = function(instance) { */ create : function(data, options) { var self = this; - ignore_readonly(data, options, true, self.context); + readonly_bypass.ignore_readonly(data, options, true, self.context); return self._super(data,options); }, /** @@ -102,7 +137,7 @@ openerp.web_readonly_bypass = function(instance) { */ write : function(id, data, options) { var self = this; - ignore_readonly(data, options, false, self.context); + readonly_bypass.ignore_readonly(data, options, false, self.context); return self._super(id,data,options); }, diff --git a/web_readonly_bypass/static/test/web_readonly_bypass.js b/web_readonly_bypass/static/test/web_readonly_bypass.js new file mode 100644 index 00000000..4aa182a9 --- /dev/null +++ b/web_readonly_bypass/static/test/web_readonly_bypass.js @@ -0,0 +1,168 @@ +openerp.testing.section( 'web_readonly_bypass', {}, +function(test){ + test('ignore_readonly', function(instance){ + openerp.web_readonly_bypass(instance); + var data = {}; + var mode_create = true; + var options = {}; + var context = {}; + instance.web_readonly_bypass.ignore_readonly(data, options, + mode_create, context); + deepEqual(data, + {}, + "Empty context and options mode create" + ); + + mode_create = false; + data = {}; + instance.web_readonly_bypass.ignore_readonly(data, options, + mode_create, context); + deepEqual(data, + {}, + "Empty context and options mode write" + ); + + mode_create = false; + data = {}; + context = {'readonly_by_pass': true}; + options = {'readonly_fields': {'field_1': 'va1-1', + 'field_2': false, + 'field_3': 'val-3'}}; + instance.web_readonly_bypass.ignore_readonly(data, options, + mode_create, context); + deepEqual(data, + {'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, + "all fields mode write" + ); + + mode_create = true; + data = {}; + context = {'readonly_by_pass': true}; + options = {'readonly_fields': {'field_1': 'va1-1', + 'field_2': false, + 'field_3': 'val-3'}}; + instance.web_readonly_bypass.ignore_readonly(data, options, + mode_create, context); + deepEqual(data, + {'field_1': 'va1-1', 'field_3': 'val-3'}, + "all fields mode create (false value are escaped)" + ); + + mode_create = true; + data = {}; + context = {}; + options = {'readonly_fields': {'field_1': 'va1-1', + 'field_2': false, + 'field_3': 'val-3'}}; + instance.web_readonly_bypass.ignore_readonly(data, options, + mode_create, context); + deepEqual(data, + {}, + "without context, default, we won't save readonly fields" + ); + }); + + test('retrieve_readonly_by_pass_fields', function(instance){ + openerp.web_readonly_bypass(instance); + var context = {'readonly_by_pass': true} + var options = {'readonly_fields': {'field_1': 'va1-1', + 'field_2': 'val-2', + 'field_3': 'val-3'}}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, + "All fields should be accepted!" + ); + + context = {'readonly_by_pass': ['field_1', 'field_3']}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {'field_1': 'va1-1','field_3': 'val-3'}, + "two field s1" + ); + + context = {'readonly_by_pass': ['field_1',]}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {'field_1': 'va1-1'}, + "Only field 1" + ); + + context = {'readonly_by_pass': []}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "Empty context field" + ); + + context = null; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "Null context" + ); + + context = false; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "false context" + ); + + context = {'readonly_by_pass': true} + options = {'readonly_fields': {'field_1': 'va1-1'}}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {'field_1': 'va1-1'}, + "Only one option" + ); + + + options = {'readonly_fields': {}}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "Empty readonly_fields option" + ); + + options = {}; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "Empty option" + ); + + options = null; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "null option" + ); + + options = false; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "false option" + ); + + context = false; + deepEqual( + instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( + options, context), + {}, + "false option and false context" + ); + }); +}); \ No newline at end of file From d650d93a69c11cb6e3c4566ce2a9c3e85a343b49 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Tue, 14 Jul 2015 14:05:31 +0200 Subject: [PATCH 5/9] document readonly_by_pass --- web_readonly_bypass/README.rst | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/web_readonly_bypass/README.rst b/web_readonly_bypass/README.rst index bf9c034f..79815358 100644 --- a/web_readonly_bypass/README.rst +++ b/web_readonly_bypass/README.rst @@ -9,8 +9,8 @@ This module provides a solution to the problem of the interaction between saving onchange modifications to readonly fields. Behavior: add readonly fields changed by `on_change` methods to the values -passed to write or create. If `filter_out_readonly` is in the context and -True then apply native behavior. +passed to write or create. If `readonly_by_pass` is in the context and +True then by pass readonly fields and save its change. Installation ============ @@ -25,11 +25,23 @@ There is nothing to configure. Usage ===== -This module changes the default behaviour of Odoo by propagating +This module changes the behaviour of Odoo by propagating on_change modifications to readonly fields to the backend create and write methods. -To restore the standard behaviour, set `filter_out_readonly` in the context. +To change that behavior you have to set context on ``ur.actions.act_window``:: + + + {'readonly_by_pass': True} + + +or by telling fields allow to change:: + + + + {'readonly_by_pass': ['readonly_field_1', 'readonly_field_2',]} + + For further information, please visit: @@ -38,7 +50,9 @@ For further information, please visit: Known issues / Roadmap ====================== -None + * At this point, bypass on a field on o2m field (like field on sale order line) + are not working, because context from action is not take on consideration + when loosing focus on the line in the ``BufferedDataSet`` js Class. Bug Tracker =========== From c6395331e7ec424db461f5801fd337e7a6b15586 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Wed, 15 Jul 2015 23:28:13 +0200 Subject: [PATCH 6/9] combine context, Get windows_action context in BufferedDataSet Class --- web_readonly_bypass/README.rst | 9 ++++----- web_readonly_bypass/static/src/js/readonly_bypass.js | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/web_readonly_bypass/README.rst b/web_readonly_bypass/README.rst index 79815358..ce17c316 100644 --- a/web_readonly_bypass/README.rst +++ b/web_readonly_bypass/README.rst @@ -10,7 +10,8 @@ saving onchange modifications to readonly fields. Behavior: add readonly fields changed by `on_change` methods to the values passed to write or create. If `readonly_by_pass` is in the context and -True then by pass readonly fields and save its change. +True then it will by pass readonly fields and save its data provide by onchange +method. Installation ============ @@ -35,7 +36,7 @@ To change that behavior you have to set context on ``ur.actions.act_window``:: {'readonly_by_pass': True} -or by telling fields allow to change:: +or by telling fields allowed to change:: @@ -50,9 +51,7 @@ For further information, please visit: Known issues / Roadmap ====================== - * At this point, bypass on a field on o2m field (like field on sale order line) - are not working, because context from action is not take on consideration - when loosing focus on the line in the ``BufferedDataSet`` js Class. + * Bug Tracker =========== diff --git a/web_readonly_bypass/static/src/js/readonly_bypass.js b/web_readonly_bypass/static/src/js/readonly_bypass.js index aa40a0d3..6ba51ce9 100644 --- a/web_readonly_bypass/static/src/js/readonly_bypass.js +++ b/web_readonly_bypass/static/src/js/readonly_bypass.js @@ -21,11 +21,8 @@ openerp.web_readonly_bypass = function(instance) { * @param {Object} context->readonly_by_pass */ ignore_readonly: function(data, options, mode, context){ - console.log(options ); - console.log(context ); var readonly_by_pass_fields = this.retrieve_readonly_by_pass_fields( options, context); - console.log(readonly_by_pass_fields ); if(mode){ $.each( readonly_by_pass_fields, function( key, value ) { if(value==false){ @@ -34,7 +31,6 @@ openerp.web_readonly_bypass = function(instance) { }); } data = $.extend(data,readonly_by_pass_fields); - console.log(data ); }, /** @@ -85,7 +81,9 @@ openerp.web_readonly_bypass = function(instance) { */ create : function(data, options) { var self = this; - readonly_bypass.ignore_readonly(data, options, true, self.context); + var context = instance.web.pyeval.eval('contexts', + self.context.__eval_context); + readonly_bypass.ignore_readonly(data, options, true, context); return self._super(data,options); }, /** @@ -99,7 +97,9 @@ openerp.web_readonly_bypass = function(instance) { */ write : function(id, data, options) { var self = this; - readonly_bypass.ignore_readonly(data, options, false, self.context); + var context = instance.web.pyeval.eval('contexts', + self.context.__eval_context); + readonly_bypass.ignore_readonly(data, options, false, context); return self._super(id,data,options); }, From c1911267f6095f33f5e277e592bbebac27cbfc4c Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 17 Jul 2015 10:56:35 +0200 Subject: [PATCH 7/9] Remove license header in __init__.py --- web_readonly_bypass/__init__.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/web_readonly_bypass/__init__.py b/web_readonly_bypass/__init__.py index 5fa4a2b1..7c68785e 100644 --- a/web_readonly_bypass/__init__.py +++ b/web_readonly_bypass/__init__.py @@ -1,28 +1 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Authors: Nemry Jonathan & Laetitia Gangloff -# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- \ No newline at end of file From 23238aa20b25fce36568965346284aa797abed26 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 17 Jul 2015 15:53:29 +0200 Subject: [PATCH 8/9] manage end of file PEP8:W292 --- web_readonly_bypass/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_readonly_bypass/__init__.py b/web_readonly_bypass/__init__.py index 7c68785e..40a96afc 100644 --- a/web_readonly_bypass/__init__.py +++ b/web_readonly_bypass/__init__.py @@ -1 +1 @@ -# -*- coding: utf-8 -*- \ No newline at end of file +# -*- coding: utf-8 -*- From 00ad8be9c5fe967f5296ade2c82d20d7e09f10cc Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 31 Jul 2015 09:37:16 +0200 Subject: [PATCH 9/9] add OCA as author --- web_readonly_bypass/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py index c07d2006..fc37b882 100644 --- a/web_readonly_bypass/__openerp__.py +++ b/web_readonly_bypass/__openerp__.py @@ -21,7 +21,7 @@ { 'name': 'Read Only ByPass', 'version': '1.0', - "author": "ACSONE SA/NV, Anybox", + "author": "ACSONE SA/NV, Anybox, Odoo Community Association (OCA)", "maintainer": "ACSONE SA/NV, Odoo Community Association (OCA)", "website": "http://www.acsone.eu", 'category': 'Technical Settings',