Odoo 10 使用 search() 方法搜索活动和非活动记录

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

我有 many2many 字段 location_from_ids 并试图找到 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})

我正在使用 search() 方法获取 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'))])

我需要获取所有位置(活动和非活动)但只获取活动记录。我怎样才能获得所有记录:活跃和不活跃?

只是 "deactivate" 主动搜索测试:

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

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

支持的操作 RecordSet 还支持您可以添加、联合和交叉的集合操作,...记录集:

recset1 中的记录 # include 记录不在 recset1 # 不包括 recset1 + recset2 # 扩展 重新设置1 | recset2 #联合 recset1 & recset2 # 相交 recset1 - recset2 # 区别 recset.copy() # 复制记录集(不是深拷贝)