diff --git a/addons/stock/static/src/fields/stock_move_line_x2_many_field.js b/addons/stock/static/src/fields/stock_move_line_x2_many_field.js index a887fcde782..6c6c8d3f6a6 100644 --- a/addons/stock/static/src/fields/stock_move_line_x2_many_field.js +++ b/addons/stock/static/src/fields/stock_move_line_x2_many_field.js @@ -3,21 +3,29 @@ import { registry } from "@web/core/registry"; import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; import { sprintf } from "@web/core/utils/strings"; -import { useSelectCreate } from "@web/views/fields/relational_utils"; +import { useSelectCreate, useOpenMany2XRecord} from "@web/views/fields/relational_utils"; export class SMLX2ManyField extends X2ManyField { setup() { super.setup(); + const selectCreate = useSelectCreate({ resModel: "stock.quant", activeActions: this.activeActions, onSelected: (resIds) => this.selectRecord(resIds), - onCreateEdit: ({ context }) => this._openRecord({ context }), + onCreateEdit: () => this.createOpenRecord(), }); this.selectCreate = (params) => { - const p = Object.assign({}, params); - return selectCreate(p); + return selectCreate(params); }; + this.openRecord = useOpenMany2XRecord({ + resModel: "stock.quant", + activeActions: this.activeActions, + onRecordSaved: (resId) => this.selectRecord([resId.data.id]), + onRecordDiscarted: (resId) => this.selectRecord(resId), + fieldString: this.props.string, + is2Many: true, + }); } async onAdd({ context, editable } = {}) { @@ -41,6 +49,22 @@ export class SMLX2ManyField extends X2ManyField { }; this.addInLine(params); } + + createOpenRecord() { + const activeElement = document.activeElement; + this.openRecord({ + context: { + ...this.props.context, + form_view_ref: "stock.view_stock_quant_form", + }, + immediate: true, + onClose: () => { + if (activeElement) { + activeElement.focus(); + } + }, + }); + } } export const smlX2ManyField = { diff --git a/addons/stock/views/stock_quant_views.xml b/addons/stock/views/stock_quant_views.xml index 7ccd2ac3ae7..703e73df3b2 100644 --- a/addons/stock/views/stock_quant_views.xml +++ b/addons/stock/views/stock_quant_views.xml @@ -397,10 +397,6 @@ in this location. That leads to a negative stock. -