跳至內容
選單
此問題已被標幟
1 回覆
90 瀏覽次數

I have created a custom module in Odoo 18 with a form view for my model.

When I open the form view (without entering any data) and then navigate to another menu or tab, Odoo automatically creates a new record with empty/default values in the database.

This results in multiple “null” or blank records being created unintentionally.


My questions:

  1. Why does Odoo create these empty records?
  2. Is this the default behavior of form views in Odoo, or is it caused by my form view setup?
  3. How can I prevent Odoo from saving a record until the user clicks Save?

Any guidance or best practices for preventing these unwanted blank records would be appreciated.

頭像
捨棄
最佳答案

If you have default values defined, the form in fact is not empty when navigating away - thus the auto-save feature hits. 


You could define a required field, without an default value, so it can't save when not set.


Alternatively you could extend the create() method and check for whatever makes you feel that the form should get saved now.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
8月 25
720
2
8月 25
306
3
8月 25
1047
1
8月 25
614
3
8月 25
915