From abfea0fff77466e268dfad8dd007a45c3ffbc0c0 Mon Sep 17 00:00:00 2001 From: Oleg Bulkin Date: Mon, 10 Oct 2016 15:16:50 -0700 Subject: [PATCH 1/2] web_widget_float_formula: Focused bug fix * Refactor to address bug reported in #431 in more focused fashion, rather than with broad try/catch --- .../static/src/js/web_widget_float_formula.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/web_widget_float_formula/static/src/js/web_widget_float_formula.js b/web_widget_float_formula/static/src/js/web_widget_float_formula.js index 76f5dd13..16411da7 100644 --- a/web_widget_float_formula/static/src/js/web_widget_float_formula.js +++ b/web_widget_float_formula/static/src/js/web_widget_float_formula.js @@ -15,7 +15,7 @@ odoo.define('web_widget_float_formula', function(require) { for (var f in this.fields) { if (!this.fields.hasOwnProperty(f)) { continue; } f = this.fields[f]; - if (f.hasOwnProperty('_formula_text')) { + if (f.hasOwnProperty('_formula_text') && f.$el.find('input').length > 0) { f._compute_result(); f._clean_formula_text(); } @@ -52,12 +52,7 @@ odoo.define('web_widget_float_formula', function(require) { }, _process_formula: function(formula) { - try{ - formula = formula.toString(); - } catch (ex) { - return false; - } - var clean_formula = formula.replace(/^\s+|\s+$/g, ''); + var clean_formula = formula.toString().replace(/^\s+|\s+$/g, ''); if (clean_formula[0] == '=') { clean_formula = clean_formula.substring(1); var myreg = new RegExp('[0-9]|\\s|\\.|,|\\(|\\)|\\+|\\-|\\*|\\/', 'g'); From f19ee39524f0fb9dbb5d114c71a216d7b78bb4cb Mon Sep 17 00:00:00 2001 From: Kelly Lougheed Date: Wed, 11 Jan 2017 18:34:36 -0800 Subject: [PATCH 2/2] [MIG] web_widget_float_formula: Migrate to 10.0 --- web_widget_float_formula/README.rst | 2 +- web_widget_float_formula/__manifest__.py | 4 ++-- .../static/src/js/web_widget_float_formula.js | 14 +++++++++++--- .../tests/js/test_web_widget_float_formula.js | 18 +++++++++--------- web_widget_float_formula/tests/test_js.py | 7 ++++--- .../views/web_widget_float_formula.xml | 2 +- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/web_widget_float_formula/README.rst b/web_widget_float_formula/README.rst index 092e8aed..4804167e 100644 --- a/web_widget_float_formula/README.rst +++ b/web_widget_float_formula/README.rst @@ -44,7 +44,7 @@ http://www.youtube.com/watch?v=jQGdD34WYrA. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/9.0 + :target: https://runbot.odoo-community.org/runbot/162/10.0 Known Issues / Roadmap ====================== diff --git a/web_widget_float_formula/__manifest__.py b/web_widget_float_formula/__manifest__.py index ac1dec59..888b1be3 100644 --- a/web_widget_float_formula/__manifest__.py +++ b/web_widget_float_formula/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Web Widget - Formulas in Float Fields', 'summary': 'Allow use of simple formulas in float fields', - 'version': '9.0.1.0.0', + 'version': '10.0.1.0.0', 'category': 'Web', 'author': 'GRAP, LasLabs, Odoo Community Association (OCA)', 'website': 'http://www.grap.coop', @@ -17,6 +17,6 @@ 'data': [ 'views/web_widget_float_formula.xml', ], - 'installable': False, + 'installable': True, 'application': False, } diff --git a/web_widget_float_formula/static/src/js/web_widget_float_formula.js b/web_widget_float_formula/static/src/js/web_widget_float_formula.js index 16411da7..065d5acf 100644 --- a/web_widget_float_formula/static/src/js/web_widget_float_formula.js +++ b/web_widget_float_formula/static/src/js/web_widget_float_formula.js @@ -35,9 +35,10 @@ odoo.define('web_widget_float_formula', function(require) { var field_float = require('web.form_widgets').FieldFloat; field_float.include({ start: function() { + this._super(); this.on('blurred', this, this._compute_result); this.on('focused', this, this._display_formula); - return this._super(); + return this; }, initialize_content: function() { @@ -52,6 +53,11 @@ odoo.define('web_widget_float_formula', function(require) { }, _process_formula: function(formula) { + try{ + formula = formula.toString(); + } catch (ex) { + return false; + } var clean_formula = formula.toString().replace(/^\s+|\s+$/g, ''); if (clean_formula[0] == '=') { clean_formula = clean_formula.substring(1); @@ -80,7 +86,9 @@ odoo.define('web_widget_float_formula', function(require) { _compute_result: function() { this._clean_formula_text(); - var formula = this._process_formula(this.$el.find('input').val()); + var input = this.$input.val(); + + var formula = this._process_formula(input); if (formula !== false) { var value = this._eval_formula(formula); if (value !== false) { @@ -95,7 +103,7 @@ odoo.define('web_widget_float_formula', function(require) { // Display the formula stored in the field to allow modification _display_formula: function() { if (this._formula_text !== '') { - this.$el.find('input').val(this._formula_text); + this.$input.val(this._formula_text); } }, }); diff --git a/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js b/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js index 808dd56e..1d7b194d 100644 --- a/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js +++ b/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js @@ -11,8 +11,8 @@ odoo.define_section('web_widget_float_formula', ['web.form_common', 'web.form_wi var field_manager = new form_common.DefaultFieldManager(null, {}); var filler = {'attrs': {}}; // Needed to instantiate FieldFloat self.field = new form_widgets.FieldFloat(field_manager, filler); - self.$element = $(''); - self.field.$el.append(self.$element); + self.field.$input = $(''); + self.field.$label = $('