solving12 solving12 - 1 year ago 221
Python Question

How to execute query in Odoo-8 from Python?

I have the following function in the class


def onchange_evalID(self):'SELECT date FROM hr_evaluation_evaluation where id=119')

Note: I'm just giving
in the query for testing purposes.

When I give %H:%M:%S")
it works fine and changes the value of field
when the value of field
changes. Again for just testing.

What I really need is to execute a query similar to what I mentioned. However when I execute this query nothing is printing on the
field. When I check the log I see this warning:

WARNING db_name openerp.models: Cannot execute name_search, no _rec_name defined on hr_evaluation.evaluation

I tried checking online why this warning, but got no help. Am I doing something wrong? How exactly can I execute query from within

Answer Source

As Hardik said, cr.execute() doesn't return directly you result. You need to fetch the values from the cursor after executing the query. Try like this:

def onchange_evalID(self):'SELECT date '
                               'FROM hr_evaluation_evaluation where id=119')
    self.deadline =[0]