How can I run a sql query after clicking a button in Odoo?

I am using Odoo8 and I am trying to create a custom module to generate a report after adding a date to the date field.

So my question is: how can I run a SQL query in a python class after clicking a button in a form?

+4
source share
1 answer

XML representation:

<button name="open_something" string="Name of button" type="object" />

Python Code:

@api.multi
def open_something(self):
    self.ensure_one()

    self.env.cr.execute("SQL query")
    result = cr.fetchall()

    ...

Keep in mind that you must use ORM methods because some restrictions are not contained in the database.

+6
source

All Articles