Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
292 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
822
2
sie 25
433
3
sie 25
1209
1
sie 25
666
3
sie 25
975