from odoo import models, fields, api
|
|
import logging
|
|
import psycopg2
|
|
|
|
from contextlib import contextmanager
|
|
import json
|
|
|
|
class fls(models.TransientModel):
|
|
_name = 'fls'
|
|
_description = 'fls data'
|
|
|
|
name = fields.Char()
|
|
description = fields.Char()
|
|
|
|
def get_data(self):
|
|
db = self.env['base.external.dbsource'].search([('name', '=', 'fls')], limit=1)
|
|
|
|
conn = db.connection_open_postgresql()
|
|
|
|
query = 'select nom from public.contact'
|
|
params=None
|
|
metadata=None
|
|
cursor = db.execute_postgresql(query,params,metadata)
|
|
|
|
self.env['fls'].search([]).unlink()
|
|
vals={}
|
|
#raise Warning(json.dumps(cursor[0][0]))
|
|
i=1
|
|
for row in cursor[0] or []:
|
|
if i==100:break
|
|
vals['name'] = row
|
|
|
|
self.create(vals)
|
|
i=i+1
|
|
|
|
db.connection_close_postgresql(conn)
|
|
action_vals = {'name': 'Transient Model from external datasource',
|
|
'type': 'ir.actions.act_window',
|
|
'view_mode': 'tree',
|
|
'res_model': 'fls',
|
|
}
|
|
return action_vals
|
|
|
|
|
|
|