odoo中的mapped

Posted yanhuaqiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了odoo中的mapped相关的知识,希望对你有一定的参考价值。

def _mapped_func(self, func):
        """ Apply function ``func`` on all records in ``self``, and return the
            result as a list or a recordset (if ``func`` returns recordsets).
        """
        if self:
            vals = [func(rec) for rec in self]
            if isinstance(vals[0], BaseModel):
                return vals[0].union(*vals)         # union of all recordsets
            return vals
        else:
            vals = func(self)
            return vals if isinstance(vals, BaseModel) else []

    def mapped(self, func):
        """ Apply ``func`` on all records in ``self``, and return the result as a
            list or a recordset (if ``func`` return recordsets). In the latter
            case, the order of the returned recordset is arbitrary.

            :param func: a function or a dot-separated sequence of field names
                (string); any falsy value simply returns the recordset ``self``
        """
        if not func:
            return self                 # support for an empty path of fields
        if isinstance(func, str):
            recs = self
            for name in func.split(‘.‘):
                recs = recs._mapped_func(operator.itemgetter(name))
            return recs
        else:
            return self._mapped_func(func)

 

self_datetime = max(self.invoice_line_ids.mapped(‘write_date‘))

func = operator.itemgetter(name) // 获取对象的name值的方法
func(rec) 获取rec的write_date值

以上是关于odoo中的mapped的主要内容,如果未能解决你的问题,请参考以下文章

RecyclerView holder中的Android Google Maps动态片段

将多个输出中的hls属性设置为单独的片段代码

odoo 怎么重写模块默认方法

odoo中的domain的所有操作符

Android Studio Map setOnMarkerClickListener 不在片段上工作

JavaScript 代码片段