Reputation: 29
I've been raking my head around this for the better part of the day and i just can't seem to get it right.
I'm trying to add a new field to the res_users form but whatever I do it just won't show. No errors, everything seems normal but the field just isn't showing in the form.
manifest.py:
{
'name': "Extended User",
'version': '1.0',
'depends': ['base'],
'author': "blake_won",
'category': 'custom',
'description': """
Description text
""",
# data files always loaded at installation
'data': [
'views/extended_views.xml',
],
}
views file:
<odoo>
<record id="res_users_form_view" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<group>
<field name="extended_variable"></field>
</group>
</xpath>
</field>
</record>
</odoo>
extendeduser.py:
from odoo import models, fields
class extendedUser(models.Model):
_inherit = 'res.users'
extended_variable = fields.Char(string="EXTENDED VARIABLE",default="NA")
console log:
2021-09-08 15:35:14,386 55731 INFO mydb odoo.modules.loading: Loading module extended_user (2/8)
2021-09-08 15:35:14,411 55731 INFO mydb odoo.modules.registry: module extended_user: creating or updating database tables
2021-09-08 15:35:14,484 55731 INFO mydb odoo.modules.loading: loading extended_user/views/extended_views.xml```
Please help me, i'm at my wit's end
Upvotes: 0
Views: 314
Reputation: 26698
As you can read in the documentation:
An
xpath
element with anexpr
attribute.expr
is an XPath expression2 applied to the current arch, the first node it finds is the match
Odoo will find the first partner_id
field, which is before the image field, and the div
containing that field will be invisible if the current user and its related partner are active.
If you check the page source code, you will find after a hyperlink named partner_id
something similar to:
<table class="o_group o_inner_group">
<tbody>
<tr>
<td class="o_td_label">
<label class="o_form_label" for="o_field_input_710" data-original-title="" title="">EXTENDED VARIABLE</label>
</td>
<td style="width: 100%;">
<span class="o_field_char o_field_widget" name="extended_variable">NA</span>
</td>
</tr>
</tbody>
</table>
Which is the rendered group
You can try to match the second partner_id
field, which is inside a group
inside a div
that has a class named oe_title
.
<xpath expr="//div[hasclass('oe_title')]/group/field[@name='partner_id']" position="after">
<field name="extended_variable"/>
</xpath>
Upvotes: 1