diff --git a/setup/web_widget_numeric_step/odoo/addons/web_widget_numeric_step b/setup/web_widget_numeric_step/odoo/addons/web_widget_numeric_step new file mode 120000 index 000000000..13aab738e --- /dev/null +++ b/setup/web_widget_numeric_step/odoo/addons/web_widget_numeric_step @@ -0,0 +1 @@ +../../../../web_widget_numeric_step \ No newline at end of file diff --git a/setup/web_widget_numeric_step/setup.py b/setup/web_widget_numeric_step/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_widget_numeric_step/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_numeric_step/README.rst b/web_widget_numeric_step/README.rst new file mode 100644 index 000000000..6a270d8db --- /dev/null +++ b/web_widget_numeric_step/README.rst @@ -0,0 +1,127 @@ +======================= +Web Widget Numeric Step +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/16.0/web_widget_numeric_step + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_numeric_step + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This widget changes input number field and make it easier to increment the number thanks to 2 buttons (+ and -). +Use JS native logic for input number, so you can use the options ``min``, ``max``, ``step``, ``placeholder``. + +Demo available at `Settings > Users & Companies > Users > *Select One* > See 'Credit Limit' field` + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In your xml view, add ``widget="numeric_step"`` +This will add the 2 buttons "+" and "-" just next to the input field in edit mode. +Iteration step by default is 1. + +.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/add_two_buttons.png + + +**Optional** + +Add an option to choose the step iteration and limits (min and max values). + +Example for an 0.25 step, min to -1 and max to 10 : + +.. code:: xml + + days + +**Available Options** + +- step > Amount to increase/decrease (default: 1.0) +- min > Min. value allowed (default: no limit) +- max > Max. value allowed (default: no limit) +- placeholder > Define the placeholder text (default: None) + +**Examples** + +Iteration with 0.25 step, min to -1 and max to 10. + +Start to increment with button, continue incrementing with scrolling mouse. + +.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/step0,25andlimits.gif + +Iteration with 10 step, max limit 15, placeholder with onchange + +.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `GRAP `_: + + * Quentin DUPONT + +* `Tecnativa `_: + + * Alexandre Díaz + * Carlos Roca + +* Helly kapatel +* Thanakrit Pintana +* Dhara Solanki + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_numeric_step/__init__.py b/web_widget_numeric_step/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_widget_numeric_step/__manifest__.py b/web_widget_numeric_step/__manifest__.py new file mode 100644 index 000000000..48eea0bfd --- /dev/null +++ b/web_widget_numeric_step/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 GRAP - Quentin DUPONT +# Copyright 2020 Tecnativa - Alexandre Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "Web Widget Numeric Step", + "category": "web", + "version": "16.0.1.0.0", + "author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/web", + "depends": ["web"], + "assets": { + "web.assets_backend": [ + "web_widget_numeric_step/static/src/xml/numeric_step.xml", + "web_widget_numeric_step/static/src/js/numeric_step.esm.js", + ], + }, + "auto_install": False, + "installable": True, +} diff --git a/web_widget_numeric_step/i18n/de.po b/web_widget_numeric_step/i18n/de.po new file mode 100644 index 000000000..c040360ba --- /dev/null +++ b/web_widget_numeric_step/i18n/de.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_numeric_step +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-10-13 20:46+0000\n" +"Last-Translator: Corneliuus \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Minus" +msgstr "Minus" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Plus" +msgstr "Plus" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Value" +msgstr "Wert" diff --git a/web_widget_numeric_step/i18n/es.po b/web_widget_numeric_step/i18n/es.po new file mode 100644 index 000000000..c577c7fac --- /dev/null +++ b/web_widget_numeric_step/i18n/es.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_numeric_step +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-08-06 11:59+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:14 +#, python-format +msgid "Minus" +msgstr "Menos" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:19 +#, python-format +msgid "Plus" +msgstr "Más" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:16 +#, python-format +msgid "Value" +msgstr "Valor" diff --git a/web_widget_numeric_step/i18n/fr.po b/web_widget_numeric_step/i18n/fr.po new file mode 100644 index 000000000..5108f7da6 --- /dev/null +++ b/web_widget_numeric_step/i18n/fr.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_number_ux_choice +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-30 12:07+0000\n" +"PO-Revision-Date: 2019-08-30 12:07+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:14 +#, python-format +msgid "Minus" +msgstr "Moins" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:19 +#, python-format +msgid "Plus" +msgstr "Plus" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:16 +#, python-format +msgid "Value" +msgstr "" diff --git a/web_widget_numeric_step/i18n/it.po b/web_widget_numeric_step/i18n/it.po new file mode 100644 index 000000000..5b8f6d8cd --- /dev/null +++ b/web_widget_numeric_step/i18n/it.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_numeric_step +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-02-04 18:44+0000\n" +"Last-Translator: Alessandro Fiorino \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Minus" +msgstr "Meno" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Plus" +msgstr "Più" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Value" +msgstr "Valore" diff --git a/web_widget_numeric_step/i18n/web_widget_numeric_step.pot b/web_widget_numeric_step/i18n/web_widget_numeric_step.pot new file mode 100644 index 000000000..835b3d94d --- /dev/null +++ b/web_widget_numeric_step/i18n/web_widget_numeric_step.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_numeric_step +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Minus" +msgstr "" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Plus" +msgstr "" + +#. module: web_widget_numeric_step +#. openerp-web +#: code:addons/web_widget_numeric_step/static/src/xml/numeric_step.xml:0 +#, python-format +msgid "Value" +msgstr "" diff --git a/web_widget_numeric_step/readme/CONTRIBUTORS.rst b/web_widget_numeric_step/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3af1d6666 --- /dev/null +++ b/web_widget_numeric_step/readme/CONTRIBUTORS.rst @@ -0,0 +1,12 @@ +* `GRAP `_: + + * Quentin DUPONT + +* `Tecnativa `_: + + * Alexandre Díaz + * Carlos Roca + +* Helly kapatel +* Thanakrit Pintana +* Dhara Solanki diff --git a/web_widget_numeric_step/readme/DESCRIPTION.rst b/web_widget_numeric_step/readme/DESCRIPTION.rst new file mode 100644 index 000000000..4f251db10 --- /dev/null +++ b/web_widget_numeric_step/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This widget changes input number field and make it easier to increment the number thanks to 2 buttons (+ and -). +Use JS native logic for input number, so you can use the options ``min``, ``max``, ``step``, ``placeholder``. + +Demo available at `Settings > Users & Companies > Users > *Select One* > See 'Credit Limit' field` diff --git a/web_widget_numeric_step/readme/USAGE.rst b/web_widget_numeric_step/readme/USAGE.rst new file mode 100644 index 000000000..fabb69723 --- /dev/null +++ b/web_widget_numeric_step/readme/USAGE.rst @@ -0,0 +1,36 @@ +In your xml view, add ``widget="numeric_step"`` +This will add the 2 buttons "+" and "-" just next to the input field in edit mode. +Iteration step by default is 1. + +.. figure:: ../static/description/add_two_buttons.png + + +**Optional** + +Add an option to choose the step iteration and limits (min and max values). + +Example for an 0.25 step, min to -1 and max to 10 : + +.. code:: xml + + days + +**Available Options** + +- step > Amount to increase/decrease (default: 1.0) +- min > Min. value allowed (default: no limit) +- max > Max. value allowed (default: no limit) +- auto_select > Select the content when the element get focus (default: False) +- placeholder > Define the placeholder text (default: None) + +**Examples** + +Iteration with 0.25 step, min to -1 and max to 10. + +Start to increment with button, continue incrementing with scrolling mouse. + +.. figure:: ../static/description/step0,25andlimits.gif + +Iteration with 10 step, max limit 15, placeholder with onchange + +.. figure:: ../static/description/step10_limit15_placeholder117_with_onchange.gif diff --git a/web_widget_numeric_step/static/description/add_two_buttons.png b/web_widget_numeric_step/static/description/add_two_buttons.png new file mode 100644 index 000000000..7a60f2dea Binary files /dev/null and b/web_widget_numeric_step/static/description/add_two_buttons.png differ diff --git a/web_widget_numeric_step/static/description/icon.png b/web_widget_numeric_step/static/description/icon.png new file mode 100644 index 000000000..3a662b992 Binary files /dev/null and b/web_widget_numeric_step/static/description/icon.png differ diff --git a/web_widget_numeric_step/static/description/index.html b/web_widget_numeric_step/static/description/index.html new file mode 100644 index 000000000..493a87c4b --- /dev/null +++ b/web_widget_numeric_step/static/description/index.html @@ -0,0 +1,466 @@ + + + + + + +Web Widget Numeric Step + + + +
+

Web Widget Numeric Step

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

This widget changes input number field and make it easier to increment the number thanks to 2 buttons (+ and -). +Use JS native logic for input number, so you can use the options min, max, step, placeholder.

+

Demo available at Settings > Users & Companies > Users > *Select One* > See ‘Credit Limit’ field

+

Table of contents

+ +
+

Usage

+

In your xml view, add widget="numeric_step" +This will add the 2 buttons “+” and “-” just next to the input field in edit mode. +Iteration step by default is 1.

+
+https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/add_two_buttons.png +
+

Optional

+

Add an option to choose the step iteration and limits (min and max values).

+

Example for an 0.25 step, min to -1 and max to 10 :

+
+<field name="sale_delay" widget="numeric_step" options="{'step': 0.25, 'min': -1, 'max': 10}" /> days
+
+

Available Options

+
    +
  • step > Amount to increase/decrease (default: 1.0)
  • +
  • min > Min. value allowed (default: no limit)
  • +
  • max > Max. value allowed (default: no limit)
  • +
  • auto_select > Select the content when the element get focus (default: False)
  • +
  • placeholder > Define the placeholder text (default: None)
  • +
+

Examples

+

Iteration with 0.25 step, min to -1 and max to 10.

+

Start to increment with button, continue incrementing with scrolling mouse.

+
+https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/step0,25andlimits.gif +
+

Iteration with 10 step, max limit 15, placeholder with onchange

+
+https://raw.githubusercontent.com/OCA/web/15.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_widget_numeric_step/static/description/step0,25andlimits.gif b/web_widget_numeric_step/static/description/step0,25andlimits.gif new file mode 100644 index 000000000..ce6780e1b Binary files /dev/null and b/web_widget_numeric_step/static/description/step0,25andlimits.gif differ diff --git a/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif b/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif new file mode 100644 index 000000000..709498e3c Binary files /dev/null and b/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif differ diff --git a/web_widget_numeric_step/static/src/js/numeric_step.esm.js b/web_widget_numeric_step/static/src/js/numeric_step.esm.js new file mode 100644 index 000000000..dcd6f233e --- /dev/null +++ b/web_widget_numeric_step/static/src/js/numeric_step.esm.js @@ -0,0 +1,92 @@ +/** @odoo-module */ + +import {registry} from "@web/core/registry"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {_lt} from "@web/core/l10n/translation"; +import {FloatField} from "@web/views/fields/float/float_field"; + +export class NumericStep extends FloatField { + setup() { + super.setup(); + } + _onFocusInput(ev) { + const $el = $(ev.target).parent().find(".widget_numeric_step_btn"); + $el.removeClass("d-none"); + } + _onFocusOutInput(ev) { + const $el = $(ev.target).find(".widget_numeric_step_btn"); + $el.addClass("d-none"); + } + _onStepClick(ev) { + const $el = $(ev.target).parent().parent().find("input"); + $el.focus(); + const mode = $(ev.target).data("mode"); + this._doStep(mode); + } + _onKeyDown(ev) { + if (ev.keyCode === $.ui.keyCode.UP) { + this._doStep("plus"); + } else if (ev.keyCode === $.ui.keyCode.DOWN) { + this._doStep("minus"); + } + } + _onWheel(ev) { + ev.preventDefault(); + if (ev.deltaY > 0) { + this._doStep("minus"); + } else { + this._doStep("plus"); + } + } + updateField(val) { + return Promise.resolve(this.props.update(val)); + } + _doStep(mode) { + let cval = this.props.value; + if (mode === "plus") { + cval += this.props.step; + } else if (mode === "minus") { + cval -= this.props.step; + } + if (cval < this.props.min) { + cval = this.props.min; + } else if (cval > this.props.max) { + cval = this.props.max; + } + this.updateField(cval); + this.props.setDirty(this._isSetDirty(cval)); + this.props.setDirty(false); + } + _isSetDirty(val) { + return this.props.value != val; + } +} + +NumericStep.template = "web_widget_numeric_step"; +NumericStep.props = { + ...standardFieldProps, + name: {type: String, optional: true}, + inputType: {type: String, optional: true}, + step: {type: Number, optional: true}, + min: {type: Number, optional: true}, + max: {type: Number, optional: true}, + placeholder: {type: String, optional: true}, +}; + +NumericStep.displayName = _lt("Numeric Step"); +NumericStep.supportedTypes = ["float"]; +NumericStep.defaultProps = { + inputType: "text", +}; +NumericStep.extractProps = ({attrs}) => { + return { + name: attrs.name, + inputType: attrs.options.type, + step: attrs.options.step || 1, + min: attrs.options.min, + max: attrs.options.max, + placeholder: attrs.options.placeholder, + }; +}; + +registry.category("fields").add("numeric_step", NumericStep); diff --git a/web_widget_numeric_step/static/src/xml/numeric_step.xml b/web_widget_numeric_step/static/src/xml/numeric_step.xml new file mode 100644 index 000000000..e645a3923 --- /dev/null +++ b/web_widget_numeric_step/static/src/xml/numeric_step.xml @@ -0,0 +1,46 @@ + + +