微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

禁用树视图 Odoo 14 中的可编辑字段

如何解决禁用树视图 Odoo 14 中的可编辑字段

我试图在此树视图中将字段设为只读,但此视图继承自 hr.employee,我们使用的是 <xpath>,并且我能够将普通字段设为只读除了 TITLE 和 ASSIGNED TO 列

或者是否可以禁用 odoo 14 中的开箱即用复选框? 谢谢!!

视图定义:

<record id="view_task_tree_rw" model="ir.ui.view">
      <field name="name">project.task.tree.inherited</field>
      <field name="model">project.task</field>
      <field name="inherit_id" ref="project.view_task_tree2"/>
      <field name="arch" type="xml">
        <xpath expr="//tree[1]/field[@name='name']" position="after">
          <field name="status"/>
          <field name="date_start" widget="date"/>
          <field name="date_end" widget="date" />
          <field name="billable"/>
          <field name="utilization"/>
          <field name="planned_hours"/>
        </xpath>
        <xpath expr="//field[@name='company_id']" position="replace"/>
        <xpath expr="//field[@name='activity_ids']" position="replace"/>
         <xpath expr="//field[@name='tag_ids']" position="replace"/>

        <xpath expr="//field[@name='stage_id']" position="replace"/>
        <xpath expr="//field[@name='project_id']" position="replace"/>
        <xpath expr="//tree[1]/field[@name='name']" position="after">
          <xpath expr="//field[@name='user_id']" position="move"/>
        </xpath>
      </field>
</record>

屏幕截图:

enter image description here

解决方法

xpath 定义中,您可以使用 position="attributes" 来覆盖继承视图的现有字段属性。所以你的代码如下:

<xpath expr="//field[@name='TARGET FIELD NAME']" position="attributes">
  <attribute name="readonly">1</attribute>
</xpath>
,

@kerbose 编写的方法是可以的,但是有时当模型有很多继承并且您不知道哪个是最后一个并且某些字段覆盖您的字段时,您可以使用优先级。优先级的默认值是 16。所以使用更高的值,因为也许将来你想在你的视图和以前的视图之间加载一些东西。

示例:

<field name="priority">50</field>

示例视图:

<record id="view_task_tree_rw_inherit_something" model="ir.ui.view">
  <field name="name">project.task.tree.inherited.inherit.something</field>
  <field name="model">project.task</field>
  <field name="priority">50</field>
  <field name="inherit_id" ref="project.view_task_tree2"/>
  <field name="arch" type="xml">
    <xpath expr="//field[@name='TARGET FIELD NAME']" position="attributes" 
     <attribute name="readonly">1</attribute>
    </xpath>

  </field>
 </record>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。