Browse Source

[MIG] web_widget_float_formula: Migrate to 10.0

pull/522/head
Kelly Lougheed 8 years ago
committed by Dave Lasley
parent
commit
f19ee39524
No known key found for this signature in database GPG Key ID: 7DDBA4BA81B934CF
  1. 2
      web_widget_float_formula/README.rst
  2. 4
      web_widget_float_formula/__manifest__.py
  3. 14
      web_widget_float_formula/static/src/js/web_widget_float_formula.js
  4. 18
      web_widget_float_formula/static/tests/js/test_web_widget_float_formula.js
  5. 7
      web_widget_float_formula/tests/test_js.py
  6. 2
      web_widget_float_formula/views/web_widget_float_formula.xml

2
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
======================

4
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,
}

14
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);
}
},
});

18
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 = $('<input>');
self.field.$el.append(self.$element);
self.field.$input = $('<input>');
self.field.$label = $('<label>');
};
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',
function(assert, 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();
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',
function(assert, 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();
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',
function(assert, 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();
assert.equal(this.$element.val(), '6');
assert.equal(this.field.$input.val(), '6');
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._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',

7
web_widget_float_formula/tests/test_js.py

@ -2,14 +2,15 @@
# Copyright 2016 LasLabs Inc.
# 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):
self.phantom_js(
"/web/tests?module=web_widget_float_formula",
"console.log('ok')",
"",
login="admin",
login="admin"
)

2
web_widget_float_formula/views/web_widget_float_formula.xml

@ -14,7 +14,7 @@
</template>
<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"/>
</xpath>
</template>

Loading…
Cancel
Save