Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
2858 Visualizzazioni
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
Abbandona
Risposta migliore

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
Abbandona

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

Risposta migliore

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
Abbandona

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.

Post correlati Risposte Visualizzazioni Attività
1
ago 24
1138
0
giu 24
910
2
lug 23
784
2
giu 24
9687
2
gen 22
47115