title: Odoo: Inherit: Replace field conditionally
body: <p>I want to do something that I've never done before and really don't have any ideas on how to solve it.</p>
  <p>What I want to do is:
  When a checkbox is checked, replace a field &quot;name&quot; with another (selection)field, but write the value to the original field &quot;name&quot;.</p>
  <p>The problem here is when I do an inherit with replace like this:</p>
  <pre><code>&lt;xpath expr=&quot;//field[@name='name']&quot; position=&quot;replace&quot;&gt;
              &lt;field name=&quot;name&quot; attrs=&quot;{'invisible': [('realman', '=', True)]}&quot;/&gt;                
              &lt;field name=&quot;workcenter_naam&quot; attrs=&quot;{'invisible': [('realman', '=', False)]}&quot; required=&quot;1&quot;/&gt;
  &lt;/xpath&gt;
  </code></pre>
  <p>(In this code, field &quot;realman&quot; is the checkbox.)</p>
  <p>It will look correct in the front end, but when I choose a value for the field &quot;workcenter_naam&quot; and click save, it gives this error:</p>
  <blockquote>
  <p>The following fields are invalid: Name</p>
  </blockquote>
  <p>If I change the name of the field &quot;workcenter_naam&quot; to &quot;name&quot; in the python file, it will ALWAYS use that field (instead of the original name field), independant of that checkbox. Like this:</p>
  <pre><code>workcenter_naam = fields.Selection(_workcentername_selection, string=&quot;Workcenter naam&quot;)
  </code></pre>
  <p>Instead of:</p>
  <pre><code>name = fields.Selection(_workcentername_selection, string=&quot;Workcenter naam&quot;)
  </code></pre>
  <p>This is what it looks like in the front end:
  <a href="https://i.stack.imgur.com/UVdTb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UVdTb.png" alt="enter image description here" /></a></p>
  <p>How it looks like in the front end, is how it should.
  The value chosen in the inherited view, for example &quot;Bakkerij&quot;, just needs to be put in the name field.</p>
  <p>Does anyone have any idea on how to solve this issue? If there is anything unclear, please let me know.</p>