代码之家  ›  专栏  ›  技术社区  ›  fueggit

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

  •  1
  • fueggit  · 技术社区  · 7 年前

    我有很多来自位置ID的字段位置,并试图找到位置ID的所有子项。

      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()方法获取位置ID的所有子项:

    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'))])
    

    我需要获取所有位置(活动和非活动),但只获取活动记录。如何获取所有记录:活动记录和非活动记录?

    1 回复  |  直到 7 年前
        1
  •  8
  •   CZoellner    7 年前

    只需“停用”搜索的活动测试:

    locations = self.env['stock.location'].with_context(
        active_test=False).search(
            [('id', 'child_of', location_ids)])
    
        2
  •  0
  •   Francisco Alvarez    6 年前

    这是对反应的补充,是对奥多记录中的歌剧的回顾 https://odoo-new-api-guide-line.readthedocs.io/en/latest/environment.html#environment

    支持的操作 记录集还支持可以添加、并集和交集等操作。。。记录集:

    记录在记录1中#包括 recset1 | recset2#接头 记录1&记录2#相交 recset1-recset2#差异 recset.copy()#复制记录集(不是深度副本)

    推荐文章