Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Two-level view inheritance, what am I missing?

By
Miku Laitinen
on 7/1/14, 2:33 AM 1,029 views

I'm trying to create a hierarchy for custom sales quotation views. I have two types of quotations; spot and tariff. They cannot be defined in the same sale.order model without violating several best practices (DRY, NF, etc.). That's why I have created an abstract class that inherits from sale.order and adds common fields and functions for both of the quotations types. The quotations then inherit sale.order (with the additional fields and functions) and redefine the model name, sale.spot and sale.tariff respectively.

The model inheritance seems to be working just as I expected, but I'm having great difficulties inheriting the views. I created a form view view_order_form_general that changes some fields in the original sale.order form view (sale.view_order_form) and my spot & tariff form views inherit from view_order_form_general. When I load the form view, there are zero modifications. If I make the spot view inherit directly from sale.view_order_form, then the modifications are applied. But only the spot modifications. Not the general ones.

Is there something that prevents multi-level inheritance or is there something else that I'm missing here?

I tried to add a drawing here to further explain the inheritance, but apparently you need 30 karma for that..

sale_general.xml (omitted openerp and data tags):

<!-- General form view -->
<record id="view_order_form_general" model="ir.ui.view">
    <field name="name">sale.order.form.general</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <data>
        ... general modifications ...
    </data>
    </field>
</record>

 

 

sale_spot.xml (omitted openerp and data tags):

<!-- Spot form view -->
<record id="view_order_form_spot" model="ir.ui.view">
    <field name="name">sale.order.form.spot</field>
    <field name="model">sale.spot</field>
    <field name="inherit_id" ref="view_order_form_general"/>
    <field name="arch" type="xml">
        <data>
        ... spot quotation specific modifications ...
    </data>
    </field>
</record>

<!-- Action for displaying spot view -->
<record id="action_spot_quotations" model="ir.actions.act_window">
    <field name="name">Spot quotations</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">sale.spot</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form,calendar,graph</field>
    <field name="search_view_id" ref="sale.view_sales_order_filter"/>
    <field name="context">{}</field>
    <field name="help" type="html">
      <p class="oe_view_nocontent_create">
        Click to create a spot quotation.
      </p>
    </field>
</record>

<!-- Which form to show for a spot quotation -->
<record id="action_spot_quotations_form" model="ir.actions.act_window.view">
    <field name="view_mode">form</field>
    <field name="view_id" ref="view_order_form_spot" />
    <field name="act_window_id" ref="action_spot_quotations" />
</record>

 

1
Timothy Solomon
On 7/1/14, 3:27 AM

There are a couple ways that you can specify which view to use. If you specify a view_id in your action_window, then it will use that. If you dont specify a view_id it will go through all the views and inherited views for that object and choose the one with the highest priority number. It looks like you have the view_ids set correctly so thats probably not the problem.

How are you over-riding the xml? are you using "replace" or inserting your tags "after" (eg <xpath expr="/form/group" position="after">)?

You could use the same view and rather hide / show the fields you need depending on whether it is a spot or tariff sale.

0
Miku Laitinen
On 7/4/14, 11:02 AM

Thank you Timothy for taking the time to answer.

Your suggestion to hide / show fields depending on the quotation type felt really tempting. The only thing I'm afraid of is that the more complex or different the quotation types grow, the more spaghetti-y views I will have.

So, I ended up copying all the fields from sale.view_order_form to my view_order_form_general. Instead of two levels of inheritance I now have only one level of inheritance for each quotation type. It seems to be working exactly as I want it to and the views will stay clean.

This answer doesn't actually solve my original problem (so I won't mark it as accepted), but it's more like a workaround. Hope it will help someone else with the same problem. I'd be very happy to see a real solution for this.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/1/14, 2:33 AM
Seen: 1029 times
Last updated: 3/16/15, 8:10 AM