Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
628 Visualizzazioni

Hi,

I'm trying to override the default form view that's opened from the Contacts menu (i.e., contacts.action_contacts) with my custom form view.

To achieve this, I've added the following record to my custom module:

<record id="action_contacts_view1" model="ir.actions.act_window.view">
    <field eval="2" name="sequence"/>
    <field name="view_mode">form</field>
    <field name="view_id" ref="my_module.view_custom_approval_form"/>
    <field name="act_window_id" ref="contacts.action_contacts"/>
</record>

This causes error:

2025-05-06 02:01:54,959 11372 ERROR odoo2 odoo.sql_db: bad query: b'INSERT INTO "ir_act_window_view" ("act_window_id", "create_date", "create_uid", "sequence", "view_id", "view_mode", "write_date", "write_uid") VALUES (153, \'2025-05-06 02:01:51.694748\', 1, 2, 1320, \'form\', \'2025-05-06 02:01:51.694748\', 1) RETURNING "id"'

ERROR: duplicate key value violates unique constraint "act_window_view_unique_mode_per_action"

DETAIL:  Key (act_window_id, view_mode)=(153, form) already exists.

he only workaround I've found is to manually delete the existing view from the database before installing:

DELETE FROM ir_act_window_view
WHERE act_window_id = (
    SELECT res_id
    FROM ir_model_data
    WHERE module = 'contacts'
      AND name = 'action_contacts'
      AND model = 'ir.actions.act_window'
)
AND view_mode = 'form';

I understand this is not a clean or safe solution.

What is the correct and clean way to override the default form view for contacts.action_contacts so that my custom form is always used without manual SQL steps?

Avatar
Abbandona
Risposta migliore

This should work:


<record id="contacts.action_contacts_view_form" model="ir.actions.act_window.view">
    <field name="view_id" ref="my_module.view_custom_approval_form"/>
</record>


With this you're essentially overriding the definition of <module>.<record>, in this case, Module:contacts (View-)Record:action_contacts_view_form

In fact, this could still be problematic upon uninstalling your module, however, it's probably your best bet.

You can find several references to this approach throughout the core source, i.e. by doing a regex search for 

<record.*\.action_


Avatar
Abbandona
Autore

Thanks you so much!

Post correlati Risposte Visualizzazioni Attività
1
giu 25
674
1
mag 25
795
1
apr 25
1228
1
mag 25
802
2
apr 25
1246