From 8ea58d83411401cda9a37bf3f7ee5ea7601562a9 Mon Sep 17 00:00:00 2001 From: achulii <96129046+achulii@users.noreply.github.com> Date: Thu, 16 May 2024 14:25:56 +0200 Subject: [PATCH] [MIG] web_widget_numeric_step: Migration to 17.0 --- web_widget_numeric_step/__manifest__.py | 2 +- .../static/src/numeric_step.esm.js | 51 +++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/web_widget_numeric_step/__manifest__.py b/web_widget_numeric_step/__manifest__.py index 6fedd89e7..950d3e718 100644 --- a/web_widget_numeric_step/__manifest__.py +++ b/web_widget_numeric_step/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Web Widget Numeric Step", "category": "web", - "version": "16.0.1.1.3", + "version": "17.0.1.0.0", "author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/OCA/web", diff --git a/web_widget_numeric_step/static/src/numeric_step.esm.js b/web_widget_numeric_step/static/src/numeric_step.esm.js index 1522132d2..09994684c 100644 --- a/web_widget_numeric_step/static/src/numeric_step.esm.js +++ b/web_widget_numeric_step/static/src/numeric_step.esm.js @@ -1,10 +1,10 @@ /** @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"; import {hasTouch} from "@web/core/browser/feature_detection"; +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"; export class NumericStep extends FloatField { setup() { @@ -19,9 +19,9 @@ export class NumericStep extends FloatField { this._doStep(mode); } _onKeyDown(ev) { - if (ev.keyCode === $.ui.keyCode.UP) { + if (ev.keyCode === 38) { this._doStep("plus"); - } else if (ev.keyCode === $.ui.keyCode.DOWN) { + } else if (ev.keyCode === 40) { this._doStep("minus"); } } @@ -34,10 +34,10 @@ export class NumericStep extends FloatField { } } updateField(val) { - return Promise.resolve(this.props.update(val)); + return this.props.record.update({[this.props.name]: val}); } _doStep(mode) { - let cval = this.props.value; + let cval = this.props.record.data[this.props.name]; if (mode === "plus") { cval += this.props.step; } else if (mode === "minus") { @@ -49,11 +49,6 @@ export class NumericStep extends FloatField { cval = this.props.max; } this.updateField(cval); - this.props.setDirty(this._isSetDirty(cval)); - this.props.setDirty(false); - } - _isSetDirty(val) { - return this.props.value != val; } } @@ -66,21 +61,25 @@ NumericStep.props = { max: {type: Number, optional: true}, placeholder: {type: String, optional: true}, }; - -NumericStep.displayName = _lt("Numeric Step"); -NumericStep.supportedTypes = ["float"]; NumericStep.defaultProps = { + ...FloatField.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, - }; + +export const numericStep = { + component: NumericStep, + supportedTypes: ["float"], + displayName: _lt("Numeric Step"), + extractProps: ({attrs, options}) => { + return { + name: attrs.name, + inputType: attrs.type, + step: options.step || 1, + min: options.min, + max: options.max, + placeholder: attrs.placeholder, + }; + }, }; -registry.category("fields").add("numeric_step", NumericStep); +registry.category("fields").add("numeric_step", numericStep);