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

I have 2 models that inherit from res.partner, using traditional class inheritance. Each subclass adds a few custom fields.

class PartnerExtA(models.Model):
_inherit = 'res.partner'
field_a = fields.Char()

class PartnerExtB(models.Model):
_inherit = 'res.partner'
field_b = fields.Char()

I need to customise the form view of each of these subclasses, and the make the customised view the default when the model is displayed.

For example, when displaying PartnerExtA, the res.partner form should look like:

name, phone, field_a   (and no other fields)

And when displaying PartnerExtB, the form should look like:

name, phone, field_b   (and no other fields)

I've tried playing with removing and adding fields using a pattern like this:
(I've removed the leading character from the xml tags as the forum was stripping the code otherwise :/ ) 

record>
field name="name">res.partner.view.form.inherit.exta
field name="model">res.partner
field name="inherit_id" ref="base.view_partner_form"/>
field name="arch" type="xml">
xpath expr="//group" position="attributes">
attribute name="invisible">1
/xpath>

xpath expr="//group" position="after">
group invisible="not field_a">
field name="name"/>
field name="phone"/>
field name="field_a"/>
/group>
/xpath>
/field>
/record>

But things get complicated with the views interacting in strange ways. 

Is there a better way to render a different view based on the concrete subclass in Odoo 17? Can I use the QWeb templating language somehow? 

Any thoughts on this gratefully received... 

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

In Odoo, you can customize the form view for each subclass of a model by creating separate XML views tailored to the specific fields of each subclass. Instead of manipulating the view through complex XML modifications, you create distinct form views for each subclass, specifying only the relevant fields for that subclass.

To achieve this, you define separate XML files for each subclass and configure them to display the appropriate fields. Then, you create actions that reference these views, ensuring that when a user accesses a record of a specific subclass, the corresponding form view is displayed.

Feel free to reach out if you have any further questions or need additional assistance.

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

Thanks for the reply Dishant. That's helpful. I guess this implies that I should be using Prototype inheritance rather than Class inheritance?

1. https://www.odoo.com/documentation/17.0/developer/tutorials/server_framework_101/12_inheritance.html#model-inheritance

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

بنة ىىلالالخههخمنفققبي انبمر برنىثقلرمنقب ؤثنثيسنمثؤىبقثبهقخبلق ىىقثىم نرىقبنمث نبىقمنلىمق ىقثمنلقثر ثقبىقمن  

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

I'm sorry I don't speak Arabic. Google translate says this means: "the daughter of the people of the world", which doesn't seem very relevant!

Bài viết liên quan Trả lời Lượt xem Hoạt động
7
thg 12 24
7730
1
thg 11 24
1702
1
thg 10 24
1821
2
thg 10 24
2491
0
thg 7 24
1084