[MIG] web_widget_numeric_step: Migration to 17.0

pull/2906/head
achulii 2024-05-16 14:25:56 +02:00 committed by Carlos Roca
parent 8ff02de12d
commit 8ea58d8341
2 changed files with 26 additions and 27 deletions

View File

@ -5,7 +5,7 @@
{ {
"name": "Web Widget Numeric Step", "name": "Web Widget Numeric Step",
"category": "web", "category": "web",
"version": "16.0.1.1.3", "version": "17.0.1.0.0",
"author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)", "author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",

View File

@ -1,10 +1,10 @@
/** @odoo-module */ /** @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 {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 { export class NumericStep extends FloatField {
setup() { setup() {
@ -19,9 +19,9 @@ export class NumericStep extends FloatField {
this._doStep(mode); this._doStep(mode);
} }
_onKeyDown(ev) { _onKeyDown(ev) {
if (ev.keyCode === $.ui.keyCode.UP) { if (ev.keyCode === 38) {
this._doStep("plus"); this._doStep("plus");
} else if (ev.keyCode === $.ui.keyCode.DOWN) { } else if (ev.keyCode === 40) {
this._doStep("minus"); this._doStep("minus");
} }
} }
@ -34,10 +34,10 @@ export class NumericStep extends FloatField {
} }
} }
updateField(val) { updateField(val) {
return Promise.resolve(this.props.update(val)); return this.props.record.update({[this.props.name]: val});
} }
_doStep(mode) { _doStep(mode) {
let cval = this.props.value; let cval = this.props.record.data[this.props.name];
if (mode === "plus") { if (mode === "plus") {
cval += this.props.step; cval += this.props.step;
} else if (mode === "minus") { } else if (mode === "minus") {
@ -49,11 +49,6 @@ export class NumericStep extends FloatField {
cval = this.props.max; cval = this.props.max;
} }
this.updateField(cval); 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}, max: {type: Number, optional: true},
placeholder: {type: String, optional: true}, placeholder: {type: String, optional: true},
}; };
NumericStep.displayName = _lt("Numeric Step");
NumericStep.supportedTypes = ["float"];
NumericStep.defaultProps = { NumericStep.defaultProps = {
...FloatField.defaultProps,
inputType: "text", inputType: "text",
}; };
NumericStep.extractProps = ({attrs}) => {
return { export const numericStep = {
name: attrs.name, component: NumericStep,
inputType: attrs.options.type, supportedTypes: ["float"],
step: attrs.options.step || 1, displayName: _lt("Numeric Step"),
min: attrs.options.min, extractProps: ({attrs, options}) => {
max: attrs.options.max, return {
placeholder: attrs.options.placeholder, 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);