Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
123 Visninger

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.

Avatar
Kassér
Bedste svar

Hi,


When you open a form view without specifying an existing record ID (for example, from a menu item pointing directly to the form), Odoo automatically calls create() in the backend to generate a new empty record. This is because Odoo’s form view is bound to a record — it needs an ID to store widget state, manage chatter, and handle relational fields. Even if you don’t type anything, just opening the form creates that blank record in the database.


In Odoo, the auto-save is triggered when a form has data (even default values) and you navigate away. If you have default values (from default_get, context, or field definitions), the form is not considered empty, so Odoo saves it when you leave. Making a required field with no default value can prevent the auto-save, because Odoo can’t save an incomplete record.


Best practices are,


- Open list view first (view_mode="tree,form") or add {'create': False} to the action context.

- Remove unnecessary defaults or make them only apply when truly creating a record.

- Override create() to block empty/null records.


Use the following module for restricting the auto save record.


* https://apps.odoo.com/apps/modules/18.0/auto_save_restrict


Hope it helps.

Avatar
Kassér
Bedste svar

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.

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
1
aug. 25
733
2
aug. 25
332
3
aug. 25
1069
1
aug. 25
620
3
aug. 25
921