Allow inheritance of views event if thay don't have the same model.

Asked by Thibaut DIRLIK (Logica)

Hi,

It's more a feature request than a bug report. Currently, you can't make a view inherit from an other if they don't have the same model_id. I believe that it might be different : You must allow this inheritance if thei repesctive models are in the same hierarchy.

Example:

Classes:
- Person
- Customer (Customer inherit from Person, but extend it, _name are different)

Views:
- Person form view
- Customer form view (inherit from person form view + some specific fields)

This kind of implementation is not possible currently. Because the Customer form view CAN'T inherit of the Persone form view : They are not working on the same model. This doesn't sound logic because a Curstomer IS A Person.

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Dony (Odoo)
Solved:
Last query:
Last reply:
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#1

Hello Thibaut,

In fact what you describe is possible, but it is an "undocumented feature".
What you want is to inherit and *copy* a view, instead of inheriting *in-place*, and patching the original view.

It works, but you need to force the view_id in the corresponding ir.actions.act_window, because otherwise the view will be ignored in both models: in the parent model because it is a different model, and on the inherited model because it is not a "top-level view", and is supposed to be applied on another view.

In your example, you can have the form view of Customer inherit the one from Person, but the action that opens the Customers must explicitly specify the view_id of that inherited view (e.g with a ir.actions.act_window.view entry)

Because this may become a FAQ, I converted this report to a Question.

Hope this helps...

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#2

Thanks for your answer, but this works only if you want to use the view from a menu/action. In the case (like in mine), where you cant to define the form view of a one2many field, it won't work.

Revision history for this message
Best Olivier Dony (Odoo) (odo-openerp) said :
#3

For to-many fields, maybe you could try using the '<type>_view_ref' context parameter to specify the view in the same manner?

You can find an example for a form view in the official addons, in sale/sale_view.xml (currently line 249):

   <field colspan="4" name="invoice_ids" nolabel="1" context="{'form_view_ref':'account.invoice_form'}"/>

The syntax works the same for any type of view, you can just add it to the context of the one2many, using '<type>_view_ref' as the key, and the XML ID of a view as the value.
In the example above, this forces the form view in the o2m to be 'account.invoice_form'.

This may work as well as with the view_id in an action.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#4

Oh my god, it works !

Really thanks for your help, after 2 days spent in this. This should REALLY be documented. If you want, I could write the doc about this feature in the 'views inheritance' part of the openobject-doc.

Thanks for everything,

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#5

It would be very appreciated if you have some time to spare to modify the documentation and mention it.
I'm sure others from the community would love it, and then you could even mark bug 658382 as fixed ;-)

I guess you're aware of that already, but just in case: anyone can push into lp:openobject-doc/trunk and the online version is rebuilt every 4 hours from the latest revision. There's more info about that stuff in the Community section at doc.openerp.com.

Thank you!

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#6

Thanks Olivier Dony (OpenERP), that solved my question.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#7

I'll do it tonight or tomorrow. The OpenERP developers documentation is really missing A LOT of things. If I can contribute, I will.