[FIX] stock: open stock quant form view to create move Lines

If no stock quant are founded in the list when adding a new move line in
the detailed operation. The `new` button opened a form view on
stock.move.line model instead of stock quant.

Task: 3256447
Part-of: odoo/odoo#122445
This commit is contained in:
William Henrotin
2023-05-30 13:03:19 +02:00
parent 1a61dc03d9
commit 233ebddef7
2 changed files with 28 additions and 8 deletions
@@ -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 = {
-4
View File
@@ -397,10 +397,6 @@ in this location. That leads to a negative stock.
<field name="owner_id" groups="stock.group_tracking_owner" invisible="context.get('readonly_form')"/>
</group>
</group>
<footer>
<button string="Confirm" class="btn btn-danger" special="save"/>
<button string="Discard" class="btn btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>