diff --git a/web_decimal_numpad_dot/README.rst b/web_decimal_numpad_dot/README.rst new file mode 100644 index 00000000..71f5e51c --- /dev/null +++ b/web_decimal_numpad_dot/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=============================== +Numpad Dot as decimal separator +=============================== + +Allows using numpad dot to enter period decimal separator even in localizations +where comma is used instead of period. + +Usage +===== + +Whenever on a float or monetary input field pressing numpad dot produces the +proper decimal separator for the active localization. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/web/162 + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Oihane Crucelaegui +* Pedro M. Baeza +* Ana Juaristi +* Omar CastiƱeira Saavedra +* Oliver Dony <@odony> +* Wim Audenaert +* David Vidal + +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 https://odoo-community.org. diff --git a/web_decimal_numpad_dot/__init__.py b/web_decimal_numpad_dot/__init__.py new file mode 100644 index 00000000..dae354a6 --- /dev/null +++ b/web_decimal_numpad_dot/__init__.py @@ -0,0 +1 @@ +# -*- encoding: utf-8 -*- diff --git a/web_decimal_numpad_dot/__manifest__.py b/web_decimal_numpad_dot/__manifest__.py new file mode 100644 index 00000000..457c130b --- /dev/null +++ b/web_decimal_numpad_dot/__manifest__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 AvanzOSC - Oihane Crucelaegui +# Copyright 2015 Tecnativa - Pedro M. Baeza +# Copyright 2015 Comunitea - Omar CastiƱeira Saavedra +# Copyright 2016 Oliver Dony +# Copyright 2017 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Web - Numpad Dot as decimal separator", + "version": "10.0.1.0.0", + "license": "AGPL-3", + "summary": "Allows using numpad dot to enter period decimal separator", + "depends": [ + "web", + ], + "author": "AvanzOSC, " + "Comunitea, " + "Tecnativa, " + "Odoo Community Association (OCA)", + "website": "https://odoo-community.org/", + "category": "Web", + "data": [ + "views/web_decimal_numpad_dot.xml", + ], + "installable": True, +} diff --git a/web_decimal_numpad_dot/static/description/icon.png b/web_decimal_numpad_dot/static/description/icon.png new file mode 100644 index 00000000..9c205cbc Binary files /dev/null and b/web_decimal_numpad_dot/static/description/icon.png differ diff --git a/web_decimal_numpad_dot/static/src/js/numpad_dot.js b/web_decimal_numpad_dot/static/src/js/numpad_dot.js new file mode 100644 index 00000000..8d227803 --- /dev/null +++ b/web_decimal_numpad_dot/static/src/js/numpad_dot.js @@ -0,0 +1,34 @@ +/* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +odoo.define("web_decimal_numpad_dot.FieldFloat", function (require) { + "use strict"; + + var form_widgets = require("web.form_widgets"); + var translation = require("web.translation"); + + form_widgets.FieldFloat.include({ + init: function () { + this.events.keypress = function (event) { + if (event.which === 46 || event.which === 44) { + event.preventDefault(); + var input = this.$input || this.$("input"); + var l10n = translation._t.database.parameters; + if (!_.str.contains(input.val(), l10n.decimal_point)) { + try { + var caret_pos = input[0].selectionStart; + var selection_end = input[0].selectionEnd; + var cur_val = input.val(); + var newval = cur_val.substring(0, caret_pos) + l10n.decimal_point + cur_val.substring(selection_end); + input.val(newval); + input[0].selectionStart = input[0].selectionEnd = caret_pos + 1; + } catch (error) { + //fallback to appending if no caret position can be determined + input.val(input.val() + l10n.decimal_point); + } + } + } + }; + return this._super.apply(this, arguments); + } + }); +}); diff --git a/web_decimal_numpad_dot/views/web_decimal_numpad_dot.xml b/web_decimal_numpad_dot/views/web_decimal_numpad_dot.xml new file mode 100644 index 00000000..d4815753 --- /dev/null +++ b/web_decimal_numpad_dot/views/web_decimal_numpad_dot.xml @@ -0,0 +1,11 @@ + + + + + +