콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
6 답글
41795 화면

Hello,

In a module that I've created (class miadi_packaging), I want to do a SELECT query on the product.product table.

How can I do it ?


Thanks for help

아바타
취소
베스트 답변

Hello MIADi,

its not product.product. You should write like this produits = self._cr.execute("SELECT display_name FROM product_product")  .

Postgres takes as product_product instead what we give in ODOO _name = 'product.product'

eg sale.order in ODOO takes as sale_order in Postgres.

아바타
취소
베스트 답변

Hi MIADI,

Usually you do this with the default ORM functions from Odoo. In this case with self.env where you do a search on your table:

# Will get any record from the table product.product
results = self.env['product.product'].search([])
# Will only get products where there is a price filled in:
results = self.env['product.product'].search([('lst_price', '!=', 0)])

You can also execute SQL queries to postgreSQL thanks to the cursor that is available in any method within Odoo. This will, however, bypass all the safety checks and features in Odoo.  An example of code:

result = self._cr.execute('select * from product_product')
# Do something with your results here.

Usually it is best to use the ORM but if you wish to query a lot of records and only need one specific field a cursor will be a lot faster.
For more information see https://www.odoo.com/documentation/10.0/reference/orm.html#environment


Regards,

Yenthe

아바타
취소

Hello Yenthe, When I execute this res = self._cr.execute('select * from simple_controller') I Got None in res

Got It.

self._cr.execute('select * from simple_controller')

for res in self.env.cr.fetchall():

print res

베스트 답변

The Query is "select name from product_template" . Product name is in model product.template not in product.product .

아바타
취소
작성자

Hi, yes we can get the name with this but I want the name of the product and the variants like this : "iPod (16)" and "iPod (32 Go)" but now, I've "iPod"

작성자 베스트 답변

Hi, Annadurai

Thanks, it was the error but it's tell me another issue : la colonne "display_name" n'existe pas. However, I think it exists.

So, can you tell me how can I take the name of the product in my SQL query ?

Regards,

MIADI

아바타
취소

look at the table structures and use joins.