odoo-addons/pos_edit_order_line/static/src/js/EditOrderLineInput.js

45 lines
1.5 KiB
JavaScript

odoo.define("pos_edit_order_line.EditOrderLineInput", function (require) {
"use strict";
const {useState} = owl;
const PosComponent = require("point_of_sale.PosComponent");
const Registries = require("point_of_sale.Registries");
class EditOrderLineInput extends PosComponent {
setup() {
super.setup();
this.state = useState({
quantityInput: this.props.item.quantity,
priceInput: this.props.item.price,
discountInput: this.props.item.discount,
});
this.changes = {
quantityInput: this.props.item.quantity,
priceInput: this.props.item.price,
discountInput: this.props.item.discount,
};
}
onChange() {
const id = this.props.item.id;
const value = parseFloat(event.target.value.trim());
if (isNaN(value)) {
$(event.target).addClass("required");
} else {
$(event.target).removeClass("required");
}
if (this.props.item[event.target.name] !== value) {
this.changes[event.target.name] = value;
this.trigger("onchange", {id, changes: this.changes});
}
}
onFocus(event) {
$(event.target).select();
}
}
EditOrderLineInput.template = "EditOrderLineInput";
Registries.Component.add(EditOrderLineInput);
return EditOrderLineInput;
});