添加功能
This commit is contained in:
@@ -11,19 +11,19 @@ patch(Many2ManyTagsFieldColorEditable, {
|
|||||||
});
|
});
|
||||||
patch(Many2ManyTagsFieldColorEditable.prototype, {
|
patch(Many2ManyTagsFieldColorEditable.prototype, {
|
||||||
async onBadgeClick(ev, record) {
|
async onBadgeClick(ev, record) {
|
||||||
if (!this.props.canEditColor) {
|
const context = record.evalContext?.context || {};
|
||||||
const context = record.evalContext?.context || {};
|
// 优先处理 open_form_view:显式指定打开某个表单视图(如分公司标签),
|
||||||
|
// 不受 canEditColor 颜色弹窗逻辑影响,确保点击直达指定表单。
|
||||||
|
if (context.open_form_view) {
|
||||||
let viewId = false;
|
let viewId = false;
|
||||||
if (context.open_form_view) {
|
try {
|
||||||
try {
|
viewId = await this.orm.call(
|
||||||
viewId = await this.orm.call(
|
"ir.ui.view",
|
||||||
"ir.ui.view",
|
"get_view_id_from_xmlid",
|
||||||
"get_view_id_from_xmlid",
|
[context.open_form_view]
|
||||||
[context.open_form_view]
|
);
|
||||||
);
|
} catch (error) {
|
||||||
} catch (error) {
|
console.error("获取指定 XML ID 的视图 ID 失败:", context.open_form_view, error);
|
||||||
console.error("获取指定 XML ID 的视图 ID 失败:", context.open_form_view, error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.env.services.action.doAction({
|
this.env.services.action.doAction({
|
||||||
type: "ir.actions.act_window",
|
type: "ir.actions.act_window",
|
||||||
@@ -33,7 +33,22 @@ patch(Many2ManyTagsFieldColorEditable.prototype, {
|
|||||||
views: [[viewId, "form"]],
|
views: [[viewId, "form"]],
|
||||||
target: "new",
|
target: "new",
|
||||||
context: {
|
context: {
|
||||||
edit: false,
|
edit: true,
|
||||||
|
create: false
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.props.canEditColor) {
|
||||||
|
this.env.services.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
name: record?.data?.display_name,
|
||||||
|
res_model: this.relation,
|
||||||
|
res_id: record.resId,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "new",
|
||||||
|
context: {
|
||||||
|
edit: true,
|
||||||
create: false
|
create: false
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -94,7 +109,7 @@ patch(Many2ManyTagsField.prototype, {
|
|||||||
views: [[viewId, "form"]],
|
views: [[viewId, "form"]],
|
||||||
target: "new",
|
target: "new",
|
||||||
context: {
|
context: {
|
||||||
edit: false,
|
edit: true,
|
||||||
create: false
|
create: false
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,58 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="yuthon_hr_employee_view_company_form" model="ir.ui.view">
|
<!--
|
||||||
|
分公司表单视图(自包含,不继承 base.view_company_form)
|
||||||
|
原因:线上 base.view_company_form 外部标识被污染指向了 account.journal.form,
|
||||||
|
任何继承它的视图都会报 ParseError。这里从根写一个独立表单,
|
||||||
|
由 many2many_tags_preview 的 open_form_view 上下文按需打开,彻底绕开污染。
|
||||||
|
-->
|
||||||
|
<record id="yuthon_hr_employee_res_company_form" model="ir.ui.view">
|
||||||
<field name="name">yuthon.hr.employee.res.company.form</field>
|
<field name="name">yuthon.hr.employee.res.company.form</field>
|
||||||
<field name="model">res.company</field>
|
<field name="model">res.company</field>
|
||||||
<field name="inherit_id" ref="base.view_company_form"/>
|
<field name="priority">50</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<!-- 确保分公司名称字段在标签点击弹窗场景下始终可编辑 -->
|
<form string="分公司">
|
||||||
<xpath expr="//field[@name='name']" position="attributes">
|
<sheet>
|
||||||
<attribute name="readonly">0</attribute>
|
<div class="oe_title">
|
||||||
<attribute name="invisible">0</attribute>
|
<h1>
|
||||||
|
<field name="name" readonly="0" placeholder="分公司名称"/>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<group>
|
||||||
|
<group>
|
||||||
|
<field name="parent_id"/>
|
||||||
|
<field name="child_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="email"/>
|
||||||
|
<field name="phone"/>
|
||||||
|
<field name="website"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="street"/>
|
||||||
|
<field name="street2"/>
|
||||||
|
<field name="zip"/>
|
||||||
|
<field name="city"/>
|
||||||
|
<field name="country_id"/>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
在公司列表的“分公司”标签列(child_ids, widget=many2many_tags) 注入 open_form_view,
|
||||||
|
点击标签时 many2many_tags_preview 会按 xmlid 打开上面自包含的表单(可编辑)。
|
||||||
|
精确匹配 widget='many2many_tags' 的那个,避免影响层级区里另一个 child_ids。
|
||||||
|
-->
|
||||||
|
<record id="yuthon_hr_employee_view_company_tree_ctx" model="ir.ui.view">
|
||||||
|
<field name="name">yuthon.hr.employee.res.company.tree.ctx</field>
|
||||||
|
<field name="model">res.company</field>
|
||||||
|
<field name="inherit_id" ref="base.view_company_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='child_ids' and @widget='many2many_tags']" position="attributes">
|
||||||
|
<attribute name="context">{'open_form_view': 'yuthon_hr_employee.res.company.form'}</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user