SQL odoo 9 函数中的语句

SQL statment in odoo 9 function

如何在函数中创建 sql odoo 9 中的语句?

我想调用 my_function 并打印数据库中的所有记录。

例如:select time_start 从时间 time_start >= 'TODAY''

def my_function(self):
        result = []
        for data in self.browse():
            cr.execute('''select
                    time_start
                from
                    time
                where
                    time_start >= 'TODAY''')
        print all result line by line

尝试

def my_function(self):
   result = []
   for data in self.browse():
      cr.execute('''select
                    time_start
                from
                    time
                where
                    time_start >= 'TODAY''')

      for line in cr.dictfetchall():
         print line["time_start"]
         print line

cr.dictfetchall() returns 字典列表。此列表中的每个元素代表您的查询结果中的一行。

在我的解决方案中,我遍历了这个列表,可以通过数据库中的字段名直接访问该字段。

请注意,在循环中使用查询。可能有更好的方法。

编辑:尝试 search 而不是 browsebrowse 为您提供给定 ID 的匹配记录。

def my_function(self):
   result = []
   for data in self.search([]):
      cr.execute('''select
                    time_start
                from
                    time
                where
                    time_start >= 'TODAY''')

      for line in cr.dictfetchall():
         print line["time_start"]
         print line