Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
2867 Ansichten
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?


Avatar
Verwerfen
Beste Antwort

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,

Avatar
Verwerfen

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

Beste Antwort

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>'}" 


Avatar
Verwerfen

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.

Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Aug. 24
1145
0
Juni 24
910
2
Juli 23
784
2
Juni 24
9688
2
Jan. 22
47118