【问题标题】:Odoo 10 search active and inactive records using search() methodOdoo 10 使用 search() 方法搜索活动和非活动记录
【发布时间】:2018-12-10 14:53:21
【问题描述】:

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

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

【问题讨论】:

    标签: python-2.7 orm odoo odoo-10


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 您好,您可以用英文发表您的答案吗?
      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多