[IMP] web: open m2o record in target current
This commit adds an option to many2one field to open the record either in target new (dialog) or target current (replace view) which is now the default. task id: 2822553 X-original-commit: abe26f6eebb450512b35c25094329f85b98c15d9 Part-of: odoo/odoo#101118
This commit is contained in:
@@ -188,7 +188,11 @@ export class Many2OneField extends Component {
|
||||
}
|
||||
}
|
||||
onExternalBtnClick() {
|
||||
this.openDialog(this.resId);
|
||||
if (this.props.openTarget === "current") {
|
||||
this.openAction();
|
||||
} else {
|
||||
this.openDialog(this.resId);
|
||||
}
|
||||
}
|
||||
async onBarcodeBtnClick() {
|
||||
const barcode = await BarcodeScanner.scanBarcode();
|
||||
@@ -259,6 +263,7 @@ Many2OneField.props = {
|
||||
relation: { type: String, optional: true },
|
||||
string: { type: String, optional: true },
|
||||
canScanBarcode: { type: Boolean, optional: true },
|
||||
openTarget: { type: String, validate: (v) => ["current", "new"].includes(v), optional: true },
|
||||
};
|
||||
Many2OneField.defaultProps = {
|
||||
canOpen: true,
|
||||
@@ -270,6 +275,7 @@ Many2OneField.defaultProps = {
|
||||
searchLimit: 7,
|
||||
string: "",
|
||||
canScanBarcode: false,
|
||||
openTarget: "current",
|
||||
};
|
||||
|
||||
Many2OneField.displayName = _lt("Many2one");
|
||||
@@ -295,6 +301,7 @@ Many2OneField.extractProps = ({ attrs, field }) => {
|
||||
string: attrs.string || field.string,
|
||||
createNameField: attrs.options.create_name_field,
|
||||
canScanBarcode: canScanBarcode,
|
||||
openTarget: attrs.open_target,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
<t t-if="hasExternalButton">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary fa fa-external-link o_external_button"
|
||||
class="btn btn-secondary fa o_external_button"
|
||||
t-att-class="props.openTarget === 'current' ? 'fa-arrow-right' : 'fa-external-link'"
|
||||
tabindex="-1"
|
||||
draggable="false"
|
||||
aria-label="External link"
|
||||
|
||||
@@ -4209,4 +4209,67 @@ QUnit.module("Fields", (hooks) => {
|
||||
"Placeholder"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("open_target prop = current", async function (assert) {
|
||||
serverData.views = {
|
||||
"partner,false,form": '<form><field name="trululu" open_target="current"/></form>',
|
||||
"partner,false,search": "<search></search>",
|
||||
};
|
||||
serverData.actions = {
|
||||
1: {
|
||||
name: "Partner",
|
||||
res_model: "partner",
|
||||
res_id: 1,
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "form"]],
|
||||
},
|
||||
};
|
||||
const webClient = await createWebClient({
|
||||
serverData,
|
||||
mockRPC(route, { method }) {
|
||||
if (method === "get_formview_action") {
|
||||
assert.step("get_formview_action");
|
||||
return {
|
||||
type: "ir.actions.act_window",
|
||||
res_model: "partner",
|
||||
view_type: "form",
|
||||
view_mode: "form",
|
||||
views: [[false, "form"]],
|
||||
target: "current",
|
||||
res_id: false,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
await doAction(webClient, 1);
|
||||
|
||||
await selectDropdownItem(target, "trululu", "first record");
|
||||
assert.containsOnce(target, ".o_field_widget .o_external_button.fa-arrow-right");
|
||||
await click(target, ".o_field_widget .o_external_button");
|
||||
|
||||
assert.verifySteps(["get_formview_action"]);
|
||||
assert.strictEqual(target.querySelector(".breadcrumb").textContent, "first recordNew");
|
||||
});
|
||||
|
||||
QUnit.test("open_target prop = new", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: '<form><field name="trululu" open_target="new" /></form>',
|
||||
mockRPC(route, { method }) {
|
||||
if (method === "get_formview_id") {
|
||||
assert.step("get_formview_id");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await selectDropdownItem(target, "trululu", "first record");
|
||||
assert.containsOnce(target, ".o_field_widget .o_external_button.fa-external-link");
|
||||
await click(target, ".o_field_widget .o_external_button");
|
||||
|
||||
assert.verifySteps(["get_formview_id"]);
|
||||
assert.containsOnce(target, ".modal");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user