Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3552 Lượt xem

created model to inherit res.users and added 'supervisor' field and i can see this field in pgAdmin and also in Settings ->Technical -> Fields

i am trying to add 'supervisor' in user's form, please check below 2 screenshots, what am i doing wrong here? the inherited Users form not showing my custom field 'supervisor' after partner_id ( Related Partner in below form ). note i have added view file name in manifest file, also added 'base' in manifest file, then start server with upgrade the module using -u custom_module -d db_17 



plesae help.

regards

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The field PARTNER_ID appears twice in the View you are inheriting.

Your field is being added after the FIRST occurrence, which will be hidden unless the User is archived and the Contact is not:

You want to add it after the SECOND occurrence.

See https://www.odoo.com/forum/help-1/select-multiple-elements-with-xpath-116090


You may be misunderstanding the Odoo data model - a User is a set of credentials and access rights - it is not an Employee.

The Employee App already has a Manager:




Ảnh đại diện
Huỷ bỏ
Tác giả

thank you @Ray for reply.
yes, Manager is exist but the requirement is what i am trying to implement.

i have modified code (as per what i understand from link provided) but it is still not showing on user's form view, please check what i am missing or doing wrong here.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Define a new view for inherited model -->
<record id="view_custom_res_user_form" model="ir.ui.view">
<field name="name">custom.res.users.form</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'][1]" position="after">
<xpath expr="//field[@name='partner_id'][2]" position="after">
<field name="supervisor"/>
</xpath>
</xpath>
</field>
</record>
</odoo>

regards

Tác giả

The error in Odoo.log file as below:

Error while parsing or validating view:

Element '<xpath expr="//field[@name=&#39;partner_id&#39;][2]">' cannot be located in parent view

View error context:
{'file': 'd:\\program files\\odoo '
'17.0.20240101\\server\\odoo\\custom_addons\\brb_customizations\\views\\res_users_view.xml',
'line': 2,
'name': 'custom.res.users.form',
'view': ir.ui.view(1338,),
'view.model': 'res.users',
'view.parent': ir.ui.view(162,),
'xmlid': 'view_custom_res_user_form'}

.

Tác giả

sorry @Ray, by mistake i posted above error in Odoo.log please ignore it, it was because of before my posted code in your reply.

Tác giả

my first Comment to your Answer is valid, the 2nd one in which i posted error in Odoo.log is not.
waiting for your reply on my first Comment.
regards

In your first comment, you have an xpath inside an xpath and this is not supported.

If you wish to place your field after the second partner_id just reference the second partner_id - you don't need to reference the first at all

Tác giả

@Ray
i have check with code below, its not even start Odoo Server and showing errors in odoo.log file as below:
-------
Element '<xpath expr="//field[@name=&#39;partner_id&#39;][2]">' cannot be located in parent view

View error context:
{'file': 'd:\\program files\\odoo '
'17.0.20240101\\server\\odoo\\custom_addons\\brb_customizations\\views\\res_users_view.xml',
'line': 3,
'name': 'custom.res.users.form',
'view': ir.ui.view(1338,),
'view.model': 'res.users',
'view.parent': ir.ui.view(162,),
'xmlid': 'view_custom_res_user_form'}
--------

modified code as per your instruction:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Define a new view for inherited model -->
<record id="view_custom_res_user_form" model="ir.ui.view">
<field name="name">custom.res.users.form</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'][2]" position="after">
<field name="supervisor"/>
</xpath>
</field>
</record>
</odoo>

please advice and help.
regards

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 24
2359
2
thg 6 24
1530
0
thg 1 24
1754
View inheritance Đã xử lý
1
thg 3 20
3394
12
thg 12 18
34698