Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1680 Visualizzazioni

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... 

Avatar
Abbandona
Risposta migliore

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.

Avatar
Abbandona
Autore

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

Risposta migliore

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

Avatar
Abbandona
Autore

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!

Post correlati Risposte Visualizzazioni Attività
7
dic 24
7681
1
nov 24
1695
1
ott 24
1817
2
ott 24
2475
0
lug 24
1050