Ron
Ron

Reputation: 101

disable editable fields in Tree View Odoo 14

I am trying to make in this tree view the fields read only, but this view is inherited from hr.employee, and we are using <xpath>, and I am able to make the normal fields read only except for the TITLE and ASSIGNED TO columns

Or is it possible to disable that out of the box checkbox from Odoo 14? Thanks!!

View definition:

<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>

Screenshot:

enter image description here

Upvotes: 0

Views: 1332

Answers (2)

LukaszK
LukaszK

Reputation: 179

Method write by @kerbose is ok, but sometimes when there is many inherits to model and you don't know which is last and some field overwrite your field you can just use priority. The default value of priority is 16. So use more higher value because maybe in future you wanna load something between your view and previous view.

Example:

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

Sample view:

<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>

Upvotes: 1

kerbrose
kerbrose

Reputation: 1185

in xpath definition you could use position="attributes" to override an existing field attributes of the inherited view. so your code would be as following:

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

Upvotes: 1

Related Questions