From ae13a2f41e5213d7bd9490c756ebf480963b99fd Mon Sep 17 00:00:00 2001 From: "Pieter Claeys (clpi)" Date: Fri, 17 Feb 2023 10:09:24 +0000 Subject: [PATCH] [FIX] stock: inventory adjustments no update on keydown after 0 input Community PR: https://github.com/odoo/odoo/pull/112978 Since the transition of the inventory adjustments view to owl in https://github.com/odoo/odoo/commit/350a7a0d6f4816ee75676b80a9a5b9769bf80fe6, a bug was introduced in the inventory adjustments view. To reproduce: - Go to inventory adjustments page - Enter a 0 quantity in any of the Counted Quantity lines. - Press enter/tab/shift-tab to confirm. When focussing out of the field using the mouse after editing the field value, the difference field gets updated automatically, however when using a keypress as above, the field just stays the same. Solved by adding overridden `onKeydown` behaviour in the `counted_quantity_widget` similar to the existing `onInput` behaviour. closes odoo/odoo#113040 X-original-commit: 3cf3d2ba17265cc8f17facaf8a6bece0b6eddcbe Signed-off-by: Arnold Moyaux (arm) --- .../stock/static/src/widgets/counted_quantity_widget.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/stock/static/src/widgets/counted_quantity_widget.js b/addons/stock/static/src/widgets/counted_quantity_widget.js index a25421ca9a4..2237f3e44ad 100644 --- a/addons/stock/static/src/widgets/counted_quantity_widget.js +++ b/addons/stock/static/src/widgets/counted_quantity_widget.js @@ -2,6 +2,7 @@ import { FloatField, floatField } from "@web/views/fields/float/float_field"; import { registry } from "@web/core/registry"; +import { getActiveHotkey } from "@web/core/hotkeys/hotkey_service"; const { useEffect, useRef } = owl; @@ -16,8 +17,10 @@ export class CountedQuantityWidgetField extends FloatField { (inputEl) => { if (inputEl) { inputEl.addEventListener("input", this.onInput.bind(this)); + inputEl.addEventListener("keydown", this.onKeydown.bind(this)); return () => { inputEl.removeEventListener("input", this.onInput.bind(this)); + inputEl.removeEventListener("keydown", this.onKeydown.bind(this)); }; } }, @@ -30,6 +33,12 @@ export class CountedQuantityWidgetField extends FloatField { return this.props.record.update({ inventory_quantity_set: true }); } + onKeydown(ev) { + const hotkey = getActiveHotkey(ev); + if (["enter", "tab", "shift+tab"].includes(hotkey)) + this.onInput(ev) + } + get formattedValue() { if ( this.props.readonly &&