Community mailing list archives

community@mail.odoo.com

Re: Odoo 8 computed field issue

by
Yassine TEIMI
- 11/20/2015 10:26:01
@Nick,

I tried : 

                self.env.cr.execute("select value_number from survey_user_input_line where col_label='Resultat' and value_suggested_row = %s and user_input_id=%s;",(row_value,user_input_identifier))

                res = self.env.cr.fetchall()
                for value_number in res:
                    result = value_number

                record.percentage_row = float(pond)*float(result)

and here is my error : 

    record.percentage_row = float(pond)*float(result)
UnboundLocalError: local variable 'result' referenced before assignment

2015-11-20 14:59 GMT+00:00 Yassine Teimi <yteimi01@gmail.com>:
I think this commands are no longer supported, on odoo 8, I hope I'm wrong about this. 

2015-11-20 14:50 GMT+00:00 Yassine Teimi <yteimi01@gmail.com>:
Hi Nick, 

I used fetchone() to fetch my query results, it returns a list of tuples, here is my code : 

                self.env.cr.execute("select value_number from survey_user_input_line where col_label='Resultat' and value_suggested_row=115 and user_input_id=178")
                res = self.env.cr.fetchone()
                result = res[0][0]

and here is my error : 

   result = res[0][0]
TypeError: 'NoneType' object has no attribute '__getitem__'


2015-11-20 14:44 GMT+00:00 Nick Booker <nick.booker@opusvl.com>:
Hi Yassine.

Yassine Teimi <yteimi01@gmail.com> writes:

> On the other hand, do you have an idea what kind of return does :
> self.env.cr.execute('sql suery') ?

It returns nothing useful.

Do cr.fetchall() to get a list of tuples containing the results.

There's also cr.fetchone() and cr.fetchmany().

See also: http://initd.org/psycopg/docs/usage.html
          http://initd.org/psycopg/docs/cursor.html


>
> And how to use sql query parameters ? explicitly, how to use variables
> on the sql query ?

cr.execute(
    'SELECT x, y, z FROM table WHERE name = %s AND state = %s',
    (myname, mystate)
)

for x, y, z in cr.fetchall():
    # do something with x, y and z

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18



--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18



--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18