콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
2943 화면
I am working in odoo 16 and I would like to make 2 form views for the same model where one is activated when I press the button to create a new instance and the other is activated when I click on the instance in the tree view to show some specific fields of the model . Can someone tell me if it is possible and if you can provide me with a similar example?


아바타
취소
베스트 답변

Hi, we can create any number of views for same model with same mode, But we have to specify which view will be triggered in act_window records.


        <record id="action_account_journal_form" model="ir.actions.act_window">
            <field name="name">Journals</field>
            <field name="res_model">account.journal</field>
            <field name="view_mode">tree,kanban,form</field>
            <field name="view_ids" eval="[(5, 0, 0),
                (0, 0, {'view_mode': 'tree', 'view_id': ref('view_account_journal_tree')}),
                (0, 0, {'view_mode': 'kanban', 'view_id': ref('account_journal_view_kanban')}),
                (0, 0, {'view_mode': 'form', 'view_id': ref('view_account_journal_form')})]"/>
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                Add a journal
              </p><p>
                A journal is used to record transactions of all accounting data
                related to the day-to-day business.
              </p>
            </field>
        </record>

 

Here the view_ids Specifies the specific views to use for each view mode. The eval attribute indicates that this is a Python expression that will be evaluated:
(5, 0, 0): Clears existing view_ids.
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_account_journal_tree')}): Adds a tree view with the reference view_account_journal_tree.
(0, 0, {'view_mode': 'kanban', 'view_id': ref('account_journal_view_kanban')}): Adds a kanban view with the reference account_journal_view_kanban.
(0, 0, {'view_mode': 'form', 'view_id': ref('view_account_journal_form')}): Adds a form view with the reference view_account_journal_form.

 

Hope it helps,

아바타
취소

Very helpful. It worked for me. Thanks! 🫱🏻‍🫲🏻

베스트 답변

Well once you have 2 form views created

In the act window, you will need to write an exclusive form view to attach it, such that it is treated as primary view.

Example: you can refer Sale Order act window: action_orders


Then for calling a second form view from List, you can make use of context as follows:

context="{ 'form_view_ref': ...form2>'}" 


아바타
취소

This will work until the user does not refresh the page; if the user does that, then it will not open the custom view that you have passed via context.

관련 게시물 답글 화면 활동
1
8월 24
1291
0
6월 24
926
2
7월 23
784
2
6월 24
9770
2
1월 22
47265