mirror of https://github.com/OCA/web.git
[MIG] web_widget_float_formula: Migrate to 10.0
parent
abfea0fff7
commit
f19ee39524
|
@ -44,7 +44,7 @@ http://www.youtube.com/watch?v=jQGdD34WYrA.
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
: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
|
Known Issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{
|
{
|
||||||
'name': 'Web Widget - Formulas in Float Fields',
|
'name': 'Web Widget - Formulas in Float Fields',
|
||||||
'summary': 'Allow use of simple 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',
|
'category': 'Web',
|
||||||
'author': 'GRAP, LasLabs, Odoo Community Association (OCA)',
|
'author': 'GRAP, LasLabs, Odoo Community Association (OCA)',
|
||||||
'website': 'http://www.grap.coop',
|
'website': 'http://www.grap.coop',
|
||||||
|
@ -17,6 +17,6 @@
|
||||||
'data': [
|
'data': [
|
||||||
'views/web_widget_float_formula.xml',
|
'views/web_widget_float_formula.xml',
|
||||||
],
|
],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
'application': False,
|
'application': False,
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,10 @@ odoo.define('web_widget_float_formula', function(require) {
|
||||||
var field_float = require('web.form_widgets').FieldFloat;
|
var field_float = require('web.form_widgets').FieldFloat;
|
||||||
field_float.include({
|
field_float.include({
|
||||||
start: function() {
|
start: function() {
|
||||||
|
this._super();
|
||||||
this.on('blurred', this, this._compute_result);
|
this.on('blurred', this, this._compute_result);
|
||||||
this.on('focused', this, this._display_formula);
|
this.on('focused', this, this._display_formula);
|
||||||
return this._super();
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize_content: function() {
|
initialize_content: function() {
|
||||||
|
@ -52,6 +53,11 @@ odoo.define('web_widget_float_formula', function(require) {
|
||||||
},
|
},
|
||||||
|
|
||||||
_process_formula: function(formula) {
|
_process_formula: function(formula) {
|
||||||
|
try{
|
||||||
|
formula = formula.toString();
|
||||||
|
} catch (ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var clean_formula = formula.toString().replace(/^\s+|\s+$/g, '');
|
var clean_formula = formula.toString().replace(/^\s+|\s+$/g, '');
|
||||||
if (clean_formula[0] == '=') {
|
if (clean_formula[0] == '=') {
|
||||||
clean_formula = clean_formula.substring(1);
|
clean_formula = clean_formula.substring(1);
|
||||||
|
@ -80,7 +86,9 @@ odoo.define('web_widget_float_formula', function(require) {
|
||||||
_compute_result: function() {
|
_compute_result: function() {
|
||||||
this._clean_formula_text();
|
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) {
|
if (formula !== false) {
|
||||||
var value = this._eval_formula(formula);
|
var value = this._eval_formula(formula);
|
||||||
if (value !== false) {
|
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 the formula stored in the field to allow modification
|
||||||
_display_formula: function() {
|
_display_formula: function() {
|
||||||
if (this._formula_text !== '') {
|
if (this._formula_text !== '') {
|
||||||
this.$el.find('input').val(this._formula_text);
|
this.$input.val(this._formula_text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 field_manager = new form_common.DefaultFieldManager(null, {});
|
||||||
var filler = {'attrs': {}}; // Needed to instantiate FieldFloat
|
var filler = {'attrs': {}}; // Needed to instantiate FieldFloat
|
||||||
self.field = new form_widgets.FieldFloat(field_manager, filler);
|
self.field = new form_widgets.FieldFloat(field_manager, filler);
|
||||||
self.$element = $('<input>');
|
self.field.$input = $('<input>');
|
||||||
self.field.$el.append(self.$element);
|
self.field.$label = $('<label>');
|
||||||
};
|
};
|
||||||
|
|
||||||
test('Float fields should have a _formula_text property that defaults to an empty string',
|
test('Float fields should have a _formula_text property that defaults to an empty string',
|
||||||
|
@ -98,28 +98,28 @@ odoo.define_section('web_widget_float_formula', ['web.form_common', 'web.form_wi
|
||||||
test('._compute_result() should not change the value of the associated input when it is not a valid formula',
|
test('._compute_result() should not change the value of the associated input when it is not a valid formula',
|
||||||
function(assert, form_common, form_widgets, core) {
|
function(assert, form_common, form_widgets, core) {
|
||||||
window.test_setup(this, form_common, form_widgets, core);
|
window.test_setup(this, form_common, form_widgets, core);
|
||||||
this.$element.val('=2*3a');
|
this.field.$input.val('=2*3a');
|
||||||
this.field._compute_result();
|
this.field._compute_result();
|
||||||
|
|
||||||
assert.strictEqual(this.$element.val(), '=2*3a');
|
assert.strictEqual(this.field.$input.val(), '=2*3a');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('._compute_result() should not change the value of the associated input when it cannot be evaled',
|
test('._compute_result() should not change the value of the associated input when it cannot be evaled',
|
||||||
function(assert, form_common, form_widgets, core) {
|
function(assert, form_common, form_widgets, core) {
|
||||||
window.test_setup(this, form_common, form_widgets, core);
|
window.test_setup(this, form_common, form_widgets, core);
|
||||||
this.$element.val('=*/');
|
this.field.$input.val('=*/');
|
||||||
this.field._compute_result();
|
this.field._compute_result();
|
||||||
|
|
||||||
assert.strictEqual(this.$element.val(), '=*/');
|
assert.strictEqual(this.field.$input.val(), '=*/');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('._compute_result() should behave properly when the current value of the input element is a valid formula',
|
test('._compute_result() should behave properly when the current value of the input element is a valid formula',
|
||||||
function(assert, form_common, form_widgets, core) {
|
function(assert, form_common, form_widgets, core) {
|
||||||
window.test_setup(this, form_common, form_widgets, core);
|
window.test_setup(this, form_common, form_widgets, core);
|
||||||
this.$element.val('=2*3');
|
this.field.$input.val('=2*3');
|
||||||
this.field._compute_result();
|
this.field._compute_result();
|
||||||
|
|
||||||
assert.equal(this.$element.val(), '6');
|
assert.equal(this.field.$input.val(), '6');
|
||||||
assert.strictEqual(this.field._formula_text, '=2*3');
|
assert.strictEqual(this.field._formula_text, '=2*3');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ odoo.define_section('web_widget_float_formula', ['web.form_common', 'web.form_wi
|
||||||
this.field._formula_text = "test";
|
this.field._formula_text = "test";
|
||||||
this.field._display_formula();
|
this.field._display_formula();
|
||||||
|
|
||||||
assert.equal(this.$element.val(), 'test');
|
assert.equal(this.field.$input.val(), 'test');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('.start() on float fields should add a handler that calls ._compute_result() when the field is blurred',
|
test('.start() on float fields should add a handler that calls ._compute_result() when the field is blurred',
|
||||||
|
|
|
@ -2,14 +2,15 @@
|
||||||
# Copyright 2016 LasLabs Inc.
|
# Copyright 2016 LasLabs Inc.
|
||||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
from openerp.tests import HttpCase
|
import odoo.tests
|
||||||
|
|
||||||
|
|
||||||
class TestJS(HttpCase):
|
class TestJS(odoo.tests.HttpCase):
|
||||||
|
|
||||||
def test_js(self):
|
def test_js(self):
|
||||||
self.phantom_js(
|
self.phantom_js(
|
||||||
"/web/tests?module=web_widget_float_formula",
|
"/web/tests?module=web_widget_float_formula",
|
||||||
|
"console.log('ok')",
|
||||||
"",
|
"",
|
||||||
login="admin",
|
login="admin"
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="qunit_suite" name="web_widget_float_formula Test Assets" inherit_id="web.qunit_suite">
|
<template id="qunit_suite" name="web_widget_float_formula Test Assets" inherit_id="web.qunit_suite">
|
||||||
<xpath expr="//html/head" position="inside">
|
<xpath expr="//t[@t-set='head']" position="inside">
|
||||||
<script type="text/javascript" src="/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js"/>
|
<script type="text/javascript" src="/web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue