简体   繁体   English

枢转自定义模块odoo 9

[英]Pivot in custom module odoo 9

I'm try create pivot in custom module, but get error TypeError: init() takes exactly 1 argument (2 given) 我尝试在自定义模块中创建数据透视,但是出现错误TypeError:init()恰好接受1个参数(给定2个)

class ReportMyModuleUser(models.Model):
    _name = "report.my.module.user"
    _description = "My module"
    _auto = False


    name = fields.Char(string = 'Name')
    date = fields.Datetime(string = 'Date')
    user_id = fields.Many2one('res.users', 'User')


    def _select(self):
        select_str = """
             SELECT
                    pn.name,
                    pn.date,
                    pn.user_id
        """
        return select_str

    def _group_by(self):
        group_by_str = """
                GROUP BY
                    pn.name
        """
        return group_by_str

    def init(self):
        print(self)
        tools.drop_view_if_exists(self._cr, self._table)
        self._cr.execute("""
            CREATE view %s as
              %s
              FROM my_table pn
                %s
         """ % (self._table, self._select(), self._group_by()))

Any solution where is problem? 有什么解决办法吗?

Maybe is problem in .xml file? 可能是.xml文件中的问题? I don't have idea. 我不知道

You need to manage one api on above of the init as like below. 您需要在init上方管理一个api,如下所示。

@api.model_cr def init(self): print(self) tools.drop_view_if_exists(self._cr, self._table) self._cr.execute(""" CREATE view %s as %s FROM my_table pn %s """ % (self._table, self._select(), self._group_by()))

Your issue will resolve. 您的问题将会解决。

Or you can write your code in OLD api as below. 或者,您可以按以下方式在OLD API中编写代码。

def init(self, cr): print(self) tools.drop_view_if_exists(cr, self._table) cr.execute(""" CREATE or REPLACE VIEW report_my_module_user as %s FROM my_table pn %s """ % (self._select(), self._group_by()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM