odoo self.ensure_one ()

Source:

DEF ensure_one (Self): 
"" "Verifies that at The Current recorset holds A SINGLE the Record Raises.
AN Exception otherwise.
" ""
the try:
# unpack to of Ensure there IS only One value IS Faster Within last len the when to true and
# has A Significant Impact Called the Check largely the this iS AS
_id, # = self._ids she did not understand what it meant, should be the python multiple assignment, only the right side of the equal sign in the case of such an approach must be iterative
return Self
the except ValueError:
the raise ValueError ( "Expected singleton:% s"% self)

 

 

If this code is another way to well understood:

def ensure_one(self):
        """ 
      换种写法 """ if len(self) == 1:
       return self
     else: raise ValueError("Expected singleton: %s" % self)

  

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yanhuaqiang/p/11616834.html