简体   繁体   中英

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)

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? I don't have idea.

You need to manage one api on above of the init as like below.

@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.

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()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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