码迷,mamicode.com
首页 > 移动开发 > 详细

odoo中的mapped

时间:2020-01-06 12:47:29      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:mode   function   case   spl   turn   att   ret   self   方法   

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

标签:mode   function   case   spl   turn   att   ret   self   方法   

原文地址:https://www.cnblogs.com/yanhuaqiang/p/12155427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!