如何在SQL查询中获取fields.function值的值?

时间:2019-08-29 17:18:12

标签: odoo

我想使用SQL查询来提高报表的性能,但是在如何获取fields.Value中的值方面遇到了困难(即具有many2many类型且没有关系表的函数字段),如何编写SQL在这种情况下查询?

def _compute_lines(self, cr, uid, ids, name, args, context=None):
    result = {}
    for invoice in self.browse(cr, uid, ids, context=context):
        src = []
        lines = []
        if invoice.move_id:
            for m in invoice.move_id.line_id:
                if m.account_id != invoice.account_id:
                    continue
                temp_lines = []
                if m.reconcile_id:
                    temp_lines = map(lambda x: x.id, m.reconcile_id.line_id)
                elif m.reconcile_partial_id:
                    temp_lines = map(lambda x: x.id, m.reconcile_partial_id.line_partial_ids)
                lines += [x for x in temp_lines if x not in lines]
                src.append(m.id)

        lines = filter(lambda x: x not in src, lines)
        result[invoice.id] = lines
    return result




'payment_ids': fields.function(_compute_lines, relation='account.move.line', type="many2many", string='Payments', groups='base.group_user'),

1 个答案:

答案 0 :(得分:1)

  

计算字段默认情况下不存储,它们是通过计算和   根据要求返回。设置store = True会将它们存储在   数据库并自动启用搜索

来源:https://www.odoo.com/documentation/12.0/reference/orm.html#computed-fields