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