콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
5323 화면

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>

 

아바타
취소
베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
View inheritance 해결 완료
1
3월 20
2734
12
12월 18
33884
1
7월 16
6311
1
3월 15
7058
0
3월 15
3391