Skip to content

Commit

Permalink
[MIG] web_widget_numeric_step: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Dec 23, 2024
1 parent 0889f10 commit 500ef34
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 38 deletions.
16 changes: 8 additions & 8 deletions web_widget_numeric_step/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Web Widget Numeric Step
: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/17.0/web_widget_numeric_step
:target: https://github.com/OCA/web/tree/18.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-17-0/web-17-0-web_widget_numeric_step
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_numeric_step
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -89,17 +89,17 @@ You can test the feature by going to Settings > Technical > Scheduled
Actions. The field "Execute Every" is configured to use the widget with
2 step, min to 0 and max to 40.

.. |image1| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/add_two_buttons.png
.. |image2| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/step0,25andlimits.gif
.. |image3| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif
.. |image1| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/add_two_buttons.png
.. |image2| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/step0,25andlimits.gif
.. |image3| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_numeric_step%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_numeric_step%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -152,6 +152,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-rafaelbn| |maintainer-yajo|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/17.0/web_widget_numeric_step>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_widget_numeric_step>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion web_widget_numeric_step/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Web Widget Numeric Step",
"category": "web",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "GRAP, Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
Expand Down
12 changes: 6 additions & 6 deletions web_widget_numeric_step/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Web Widget Numeric Step</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1062d0c26bb10198c524113d70fa069c5928514e9569f607316544fee88bb6d9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/17.0/web_widget_numeric_step"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_widget_numeric_step"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_widget_numeric_step"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_numeric_step"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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 <tt class="docutils literal">min</tt>, <tt class="docutils literal">max</tt>, <tt class="docutils literal">step</tt>,
Expand All @@ -394,7 +394,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>In your xml view, add <tt class="docutils literal"><span class="pre">widget=&quot;numeric_step&quot;</span></tt> This will add the 2
buttons “+” and “-” just next to the input field in edit mode. Iteration
step by default is 1.</p>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/add_two_buttons.png" /></p>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/add_two_buttons.png" /></p>
<p><strong>Optional</strong></p>
<p>Add an option to choose the step iteration and limits (min and max
values).</p>
Expand All @@ -415,9 +415,9 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>Iteration with 0.25 step, min to -1 and max to 10.</p>
<p>Start to increment with button, continue incrementing with scrolling
mouse.</p>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/step0,25andlimits.gif" /></p>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/step0,25andlimits.gif" /></p>
<p>Iteration with 10 step, max limit 15, placeholder with onchange</p>
<p><img alt="image3" src="https://raw.githubusercontent.com/OCA/web/17.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif" /></p>
<p><img alt="image3" src="https://raw.githubusercontent.com/OCA/web/18.0/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif" /></p>
<p><strong>Demo</strong></p>
<p>You can test the feature by going to Settings &gt; Technical &gt; Scheduled
Actions. The field “Execute Every” is configured to use the widget with
Expand All @@ -428,7 +428,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_numeric_step%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_numeric_step%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -468,7 +468,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/rafaelbn"><img alt="rafaelbn" src="https://github.com/rafaelbn.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/yajo"><img alt="yajo" src="https://github.com/yajo.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/17.0/web_widget_numeric_step">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/18.0/web_widget_numeric_step">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
63 changes: 41 additions & 22 deletions web_widget_numeric_step/static/src/numeric_step.esm.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
/** @odoo-module */

import {_lt} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";
import {FloatField} from "@web/views/fields/float/float_field";
import {standardFieldProps} from "@web/views/fields/standard_field_props";
import {_t} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";

export class NumericStep extends FloatField {
setup() {
super.setup();
this.throttleTimer = null;
this.lastAssignedValue = this.props.record.data[this.props.name];
this.tempValue = this.lastAssignedValue;
}
willUpdateProps(nextProps) {
super.willUpdateProps(nextProps);
const newVal = nextProps.record.data[nextProps.name];
if (newVal !== this.lastAssignedValue) {
this.lastAssignedValue = newVal;
this.tempValue = newVal;
}
}
get value() {
return this.tempValue;
}
_onStepClick(ev) {
const mode = $(ev.target).data("mode");
const mode = ev.target.dataset?.mode;
this._doStep(mode);
}
_onKeyDown(ev) {
if (ev.keyCode === 38) {
if (ev.key === "ArrowUp") {
this._doStep("plus");
} else if (ev.keyCode === 40) {
} else if (ev.key === "ArrowDown") {
this._doStep("minus");
}
}
Expand All @@ -28,28 +39,36 @@ export class NumericStep extends FloatField {
this._doStep("plus");
}
}
updateField(val) {
return this.props.record.update({[this.props.name]: val});
}
_doStep(mode) {
let cval = this.props.record.data[this.props.name];
let val = this.tempValue;
if (mode === "plus") {
cval += this.props.step;
} else if (mode === "minus") {
cval -= this.props.step;
val += this.props.step;
} else {
val -= this.props.step;
}
if (cval < this.props.min) {
cval = this.props.min;
} else if (cval > this.props.max) {
cval = this.props.max;
if (val < this.props.min) {
val = this.props.min;
} else if (val > this.props.max) {
val = this.props.max;
}
this.updateField(cval);
this.tempValue = val;
// eslint-disable-next-line no-undef
clearTimeout(this.throttleTimer);
// eslint-disable-next-line no-undef
this.throttleTimer = setTimeout(() => {
this._applyFinalChange(val);
}, 100);
}
_applyFinalChange(val) {
this.props.record.data[this.props.name] = val;
this.lastAssignedValue = val;
this.props.record.update({[this.props.name]: val});
}
}

NumericStep.template = "web_widget_numeric_step";
NumericStep.props = {
...standardFieldProps,
...FloatField.props,
inputType: {type: String, optional: true},
step: {type: Number, optional: true},
min: {type: Number, optional: true},
Expand All @@ -64,7 +83,7 @@ NumericStep.defaultProps = {
export const numericStep = {
component: NumericStep,
supportedTypes: ["float"],
displayName: _lt("Numeric Step"),
displayName: _t("Numeric Step"),
extractProps: ({attrs, options}) => {
return {
name: attrs.name,
Expand Down
2 changes: 1 addition & 1 deletion web_widget_numeric_step/static/src/numeric_step.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copyright 2020 Tecnativa - Alexandre Díaz
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<template>
<t t-name="web_widget_numeric_step" owl="1">
<t t-name="web_widget_numeric_step">
<div class="d-flex widget_numeric_step">
<div class="input-group-prepend widget_numeric_step_btn">
<button
Expand Down

0 comments on commit 500ef34

Please sign in to comment.