Search code examples
python-2.7ormodooodoo-10

Odoo 10 search active and inactive records using search() method


I have many2many field location_from_ids and trying to find all the childs of location_ids.

  location_from_ids = fields.Many2many(comodel_name='stock.location',relation='report_stock_config_location_from_rel',column1='report_id',column2='location_id',string='Locations From', context={'active_test': False})

I am using search() method to get all the childs of location_ids:

def _get_filter(self, report):
    res = ''
    if report.location_from_ids:
        location_ids = [l.id for l in report.location_from_ids]
        locations = self.env['stock.location'].search([('id', 'child_of', location_ids), ('active', 'in', ('t', 'f'))])

I need to get all the locations (active and inactive) but getting only active records. How can I achieve to get all the records: active and inactive?


Solution

  • Just "deactivate" the active test on searches:

    locations = self.env['stock.location'].with_context(
        active_test=False).search(
            [('id', 'child_of', location_ids)])