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?