[MIG] web_widget_float_formula: v9 with i18n

* Update JS to use v9 module system
* Fix non-functioning logic for obtaining the value of an input element
* Eliminate redundant calls (e.g. there were multiple calls to eval)
* Modify formula cleanup to use localized decimal point and thousands separator
 characters
* Add JS unit tests
This commit is contained in:
Oleg Bulkin
2016-09-12 11:33:29 -07:00
parent d79a4c20ba
commit d02ce7f647
10 changed files with 369 additions and 179 deletions

View File

@@ -1,36 +1,61 @@
Allow to write simple mathematic formulas in Integer / Float fields
===================================================================
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
* Possibility to tip a text like "=45 + 4/3 - 5 * (2 +1)";
* if the formula is correct, The result will be computed and displayed;
* if the formula is not correct, the initial text is displayed;
========================
Formulas in Float Fields
========================
Technical informations
----------------------
This module allows the use of simple math formulas in integer/float fields
(e.g. "=45 + 4/3 - 5 * (2 + 1)").
* Overloads "instance.web.form.FieldFloat"; (so works for fields.integer &
fields.float);
* To compute, the module simply use the eval() javascript function;
* Rounding computation is not done by this module (The module has the same
behaviour if the user tips "=1/3" or if he tips "0.33[...]");
* avoid code injonction by regexpr test: "=alert('security')" is not valid;
* Only supports parentheses, decimal points, thousands separators, and the
operators "+", "-", "*", and "/"
* Will use the decimal point and thousands separator characters associated
with your language
* If the formula is valid, the result will be computed and displayed, and the
formula will be stored for editing
* If the formula is not valid, it's retained in the field as text
**Technical Details**
* Overloads web.form_widgets.FieldFloat (so it works for fields.integer &
fields.float)
* Uses the eval() JS function to evaluate the formula
* Does not do any rounding (this is handled elsewhere)
* Avoids code injection by applying strict regex to formula prior to eval()
(e.g. "=alert('security')" would not get evaluated)
Installation
============
To install this module, simply follow the standard install process.
Configuration
=============
No configuration is needed or possible.
Usage
=====
See demo here Video: http://www.youtube.com/watch?v=jQGdD34WYrA&hd=1
Install and enjoy. A short demo video can be found at
http://www.youtube.com/watch?v=jQGdD34WYrA.
Roadmap / Limit
===============
* Only supports the four operators: "+" "-" "*" "/" and parenthesis;
.. 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
Known Issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/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 <https://github.com/OCA/web/issues/new?body=module:%20web_widget_float_formula%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us smash it by providing detailed and welcomed
feedback.
Credits
=======
@@ -39,17 +64,19 @@ Contributors
------------
* Sylvain Le Gal (https://twitter.com/legalsylvain)
* Oleg Bulkin <o.bulkin@gmail.com>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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.
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.