Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
574 Представления

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?

Аватар
Отменить
Лучший ответ

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_


Аватар
Отменить
Автор

Thanks you so much!

Related Posts Ответы Просмотры Активность
1
июн. 25
589
1
мая 25
739
1
апр. 25
1151
1
мая 25
743
2
апр. 25
1101