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

I'm learning about developing modules. I saw two ways of adding fields in view.

One is like this:
https://www.odoo.com/documentation/12.0/howtos/backend.html#inheritance

<field name="arch" type="xml"> 
     <xpath expr="//field[@name='description']" position="after">
        <field name="idea_ids" string="Number of ideas"/>
    </xpath>
</field>


And the second one is:
https://www.cybrosys.com/blog/adding-custom-fields-to-existing-views-in-odoo-v12

<field name="arch" type="xml">
    <field name="confirmation_date" position="after">
        <field name="additional_note"/>
    </field>
</field>

What is the difference? What should I use?

Ảnh đại diện
Huỷ bỏ

Read more about inheritance in odoo: https://goo.gl/fGNfBY

Câu trả lời hay nhất

Hello,

you can both uses xpath and also field

but when complicated condition then uses xpath and normal condition then use normal field.

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

Hi!

If the modification you try to make can be done by using the field-based selection (your second example), I would always go with this solution for the sake of readability. This applies to all the cases when you try to do something directly after/before/inside some field or to that field itself.

The <xpath expr="..."> allows you to utilize the full potential of XPath to select any node inside a view. If you cannot select the specific position you are looking for via a named field, do it via XPath. :)

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

Xpath expressions gives the ability to add new pages, groups, fields to an already existing view.

Normal field gives the ability to add fields inside a already existing or new view.

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

Xpath is probably used for traverse purpose.It is mainly focused for existing one.fields are used to view purpose. 

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

Thanks for responses

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

Hi,

We can use both. 

Xpath gives you the option to add below details to an already existing view.

new pages, 

groups, 

fields and more

When you inherit an existing view in a module and required to extend it, you will need XPath expressions. 

In complicated situations, you can use Xpath or otherwise the one that you mentioned in the blog.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 19
2951
3
thg 8 19
3586
2
thg 6 20
5366
0
thg 4 19
3844
2
thg 1 19
6241