Community archives des diffusions par email
Explorer les archives
Re: Odoo 8 computed field issuepar
How to use pdb.set_trace(), and print out the values of my domain before executing search ?
On the other hand, do you have an idea what kind of return does : self.env.cr.execute('sql suery') ?
And how to use sql query parameters ? explicitly, how to use variables on the sql query ?
Thanks a lot.
2015-11-20 11:54 GMT+00:00 Yassine Teimi <email@example.com>:
Thanks houssine for the doc.Edwin, I executed the sql query from psql interface, and it worked, it returned the expected result.So I was thinking of executing the sql query from the function like this :self.env.cr.execute("select value_number from survey_user_input_line where col_label='Resultat' and value_suggested_row=? and user_input_id=?", (row_value, user_input_identifier))Considering using search method, it returns a recordset, so I did :result = self.search(domain).value_number but it didn't work. Note that i4M USING @api.multi to decorate my function.But I don't know how to use variable sql queries. Please help. Thanks.2015-11-20 11:42 GMT+00:00 Edwin Blommaerts <firstname.lastname@example.org>:Yassine,What Housine ment is run a sql query, straight from psql interface , using the expected values in your domain.If that returns a positive match then perhaps the values passed to your domain are wrong.What you could also do is use pdb and pdb.set_trace() then print out the values of your domain before executing the search.Just some small suggestions on how to debug your issue.Regards,2015-11-20 11:12 GMT+00:00 Yassine Teimi <email@example.com>:I've tested the domain on postgres, it worked, I think there is something wrong with search method.The search method retunrns a recordset, and we can access fields trough it, don't you ?2015-11-20 10:17 GMT+00:00 Houssine BAKKALI <firstname.lastname@example.org>:if the three fields of your domain are stored in the db. try your domain in postgress using filter on the table. You will be fixed of the correctness of your domain2015-11-20 10:42 GMT+01:00 Yassine Teimi <email@example.com>:Dears,I want to create a computed field, wich multiplies two different field values :The first field value is on the current record.The second field value is on another record (on the same model), and then should be searched, and retrieved, following some conditions.(I'm trying to get two values for the same field, but on two different records, of course because the field value changes from a record to another)Here is my code :from openerp import models, fields, api
_inherit = 'survey.user_input_line'
percentage_row = fields.Float('Atteinte objectif', compute='_compute_percentage_row', store=True)
for record in self:
if record.col_label == 'Pondera':
pond = record.value_number
id_token = record.user_input_id.token
row_value = record.value_suggested_row.id
domain = [('col_label','=','Resultat'),('value_suggested_row.id','=', row_value),('user_input_id.token','=', id_token)]
result = self.search(domain).value_number
record.percentage_row = float(result*pond)/100My problem is on the line in bold, it doesn't retrieve anything, the domain seems correct.Maybe there is another way to achieve my query.For further informations, it's on the survey_user_input_line object, and I'm trying to do the multiplication of two values but not on the same record.Thanks for your help, I'm blocked ...--CordialementYassine TEIMIConsultant & Odoo Project ManagerTEL : +212 6-27 33 30 78--CordialementYassine TEIMIConsultant & Odoo Project ManagerTEL : +212 6-27 33 30 78--CordialementYassine TEIMIConsultant & Odoo Project ManagerTEL : +212 6-87 71 41 18
Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18