Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
7206 Visualizações

Hi all, 

Thanks in advance for your answers.

I created a class with a model with fields 

like : 

class odoo_model(models.Model):
_name = 'sql_model'
_description = 'values from database'
  field1 = fields.Char(string="sql value", required=True, )

i created also a database view with the same fields 

like : 

create view sql_values as 

select field1 from table1


i want to update my odoo class model with values on my database view 

how can i do that ? 

please give me also a sample

Thanks a lot.  

Avatar
Cancelar
Autor

Hi Vishnu,

i am using odoo version 9

i got error that modul dont have attribute _cr

for the init

@api.model_cr

def init(self):

tools.drop_view_if_exists(self._cr, 'report_sql_test')

self._cr.execute("""CREATE or REPLACE VIEW report_sql_test ​AS (SELECT MIN(id) as id, product_id as product_id From table1) """)

You didn't mentioned the Version first time so i updated the 12 code. Now check the answer i have updated.

Melhor resposta

Hello,

Please Try Below Code

Assume you have a table as table1 and column named date and product.

#code below

from openerp import fields, models
from openerp import tools

class ReportSqlTest(models.Model): 
_name = 'report.sql.test'
_auto = False
_description = 'Sql Test Report' 

date = fields.Date(string='Date')
product_id = fields.Many2one('product.product', string='Product', readonly=True)

def init(self, cr):
tools.drop_view_if_exists(cr, 'report_sql_test') 
cr.execute("""CREATE or REPLACE VIEW report_sql_test ​AS (SELECT MIN(id) as id, product_id as product_id From table1) """)
Avatar
Cancelar
Melhor resposta

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

Avatar
Cancelar