Odoo 10 使用 search() 方法搜索活动和非活动记录 [英] Odoo 10 search active and inactive records using search() method

查看:174
本文介绍了Odoo 10 使用 search() 方法搜索活动和非活动记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 many2many 字段 location_from_ids 并试图找到 location_ids 的所有子项.

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})

我正在使用 search() 方法来获取 location_ids 的所有孩子:

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?

推荐答案

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

Just "deactivate" the active test on searches:

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

这篇关于Odoo 10 使用 search() 方法搜索活动和非活动记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆