3

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?

fueggit
  • 859
  • 1
  • 22
  • 44

2 Answers2

7

Just "deactivate" the active test on searches:

locations = self.env['stock.location'].with_context(
    active_test=False).search(
        [('id', 'child_of', location_ids)])
CZoellner
  • 13,553
  • 3
  • 25
  • 38
0

Como complemento a la respuesta, es bueno revisar las operaciones que soporta los records en odoo https://odoo-new-api-guide-line.readthedocs.io/en/latest/environment.html#environment

Supported Operations RecordSet also support set operations you can add, union and intersect, ... recordset:

record in recset1 # include record not in recset1 # not include recset1 + recset2 # extend recset1 | recset2 # union recset1 & recset2 # intersect recset1 - recset2 # difference recset.copy() # to copy recordset (not a deep copy)