CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
... general modifications ...
sale_spot.xml (omitted openerp and data tags):
<!-- Spot form view -->
<record id="view_order_form_spot" model="ir.ui.view">
<field name="inherit_id" ref="view_order_form_general"/>
<field name="arch" type="xml">
... spot quotation specific modifications ...
<!-- Action for displaying spot view -->
<record id="action_spot_quotations" model="ir.actions.act_window">
<field name="name">Spot quotations</field>
<field name="search_view_id" ref="sale.view_sales_order_filter"/>
<field name="help" type="html">
Click to create a spot quotation.
<!-- Which form to show for a spot quotation -->
<record id="action_spot_quotations_form" model="ir.actions.act_window.view">
<field name="view_id" ref="view_order_form_spot" />
<field name="act_window_id" ref="action_spot_quotations" />
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.
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.
About This Community
Odoo Training Center
|Asked: 7/1/14, 2:33 AM|
|Seen: 1347 times|
|Last updated: 3/16/15, 8:10 AM|