Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
212 Vizualizări

Hi,

I am working with Odoo Web Enterprise 17.0+e.

I have 2 different models, let's say model A and B.

I created records on both models, on B I have a many2one field that shows x_name from model A on the options.

I tried removing all records on model A but however, all x_name from model A still persist on many2one of model B and it's annoying. 

How can this happen and what can I do to remove the data?

Any help will be appreciated. Thanks!

Imagine profil
Abandonează
Cel mai bun răspuns

Hi Zulsani,

This issue usually happens because of how the many2one field works in Odoo.

Why you're still seeing the old x_name values:

Even if you’ve deleted the records from Model A, the many2one field in Model B might still show them because:

  • The records may have been archived (soft-deleted), not permanently removed.
  • Some records in Model B may still be referencing those deleted entries.

What you can do:

1. Check if records in Model A are archived:

Go to the list view of Model A and apply the "Archived" filter under the Filters menu.

If you see any archived records, either delete them permanently or unarchive as needed.

2. Check existing records in Model B:

Open some records in Model B and see if the many2one field is still pointing to records that no longer exist in Model A.

You may need to manually clear or update those fields if they reference old data.

3. Use a domain filter to show only active records:

If you’re customising the many2one field, make sure to filter out inactive or deleted records. For example:

'field_name': fields.Many2one('model.a', domain=[('active', '=', True)]) (In Python file)

<field name="your_many2one_field" domain="[('active', '=', True)]"/>

(In XML file)


Imagine profil
Abandonează
Autor

domain="[('active', '=', True)]" to the rescue. thank you so much!

Cel mai bun răspuns

Hi,


To ensure that the Many2one field in Model B only displays valid and existing records from Model A, you can optionally define the field with an ondelete behavior, such as 'set null' (to automatically clear the reference in Model B when a related record in Model A is deleted) or 'cascade' (to delete related Model B records along with Model A, use this carefully).

Example:

your_many2one_field = fields.Many2one(

    'model.a',

    string="Model A",

    ondelete='set null'  # or 'cascade'

)

If old or deleted records still appear, restart the Odoo server or clear the ORM cache.


Hope it helps

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
feb. 19
3383
1
mar. 15
5468
2
feb. 25
5709
1
dec. 24
1324
1
nov. 24
930