콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
837 화면

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!

관련 게시물 답글 화면 활동
4
8월 25
1184
1
6월 25
879
1
5월 25
988
1
4월 25
1441
1
5월 25
1027