[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) <arm@odoo.com>
This commit is contained in:
Pieter Claeys (clpi)
2023-02-21 15:53:17 +01:00
parent ef3bbc9293
commit ae13a2f41e
@@ -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 &&