Skip to Content
मेन्यू
This question has been flagged
2 Replies
334 Views

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!

Avatar
Discard
Best Answer

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)


Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
0
फ़र॰ 19
3451
1
मार्च 15
5512
2
फ़र॰ 25
5846
1
दिस॰ 24
1410
1
नव॰ 24
1004