I have a model based on a hand written sql query
I'm having this error
Errore:
Odoo Server Error
Traceback (most recent call last):
File "/home/plus/odoo/odoo/addons/base/models/ir_http\.py",\ line\ 237,\ in\ _dispatch
\ \ result\ =\ request\.dispatch\(\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 685,\ in\ dispatch
\ \ result\ =\ self\._call_function\(\*\*self\.params\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 361,\ in\ _call_function
\ \ return\ checked_call\(self\.db,\ \*args,\ \*\*kwargs\)
\ File\ "/home/plus/odoo/odoo/service/model\.py",\ line\ 94,\ in\ wrapper
\ \ return\ f\(dbname,\ \*args,\ \*\*kwargs\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 349,\ in\ checked_call
\ \ result\ =\ self\.endpoint\(\*a,\ \*\*kw\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 908,\ in\ __call__
\ \ return\ self\.method\(\*args,\ \*\*kw\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 533,\ in\ response_wrap
\ \ response\ =\ f\(\*args,\ \*\*kw\)
\ File\ "/home/plus/odoo/addons/web/controllers/main\.py",\ line\ 1372,\ in\ call_kw
\ \ return\ self\._call_kw\(model,\ method,\ args,\ kwargs\)
\ File\ "/home/plus/odoo/addons/web/controllers/main\.py",\ line\ 1364,\ in\ _call_kw
\ \ return\ call_kw\(request\.env\[model\],\ method,\ args,\ kwargs\)
\ File\ "/home/plus/odoo/odoo/api\.py",\ line\ 395,\ in\ call_kw
\ \ result\ =\ _call_kw_model\(method,\ model,\ args,\ kwargs\)
\ File\ "/home/plus/odoo/odoo/api\.py",\ line\ 368,\ in\ _call_kw_model
\ \ result\ =\ method\(recs,\ \*args,\ \*\*kwargs\)
\ File\ "/home/plus/odoo/addons/web/models/models\.py",\ line\ 99,\ in\ web_read_group
\ \ groups\ =\ self\._web_read_group\(domain,\ fields,\ groupby,\ limit,\ offset,\ orderby,\ lazy,\ expand,
\ File\ "/home/plus/odoo/addons/web/models/models\.py",\ line\ 130,\ in\ _web_read_group
\ \ groups\ =\ self\.read_group\(domain,\ fields,\ groupby,\ offset=offset,\ limit=limit,
\ File\ "/home/plus/odoo/odoo/models\.py",\ line\ 2254,\ in\ read_group
\ \ result\ =\ self\._read_group_raw\(domain,\ fields,\ groupby,\ offset=offset,\ limit=limit,\ orderby=orderby,\ lazy=lazy\)
\ File\ "/home/plus/odoo/odoo/models\.py",\ line\ 2381,\ in\ _read_group_raw
\ \ self\._cr\.execute\(query,\ where_clause_params\)
\ File\ "",\ line\ 2,\ in\ execute
\ File\ "/home/plus/odoo/odoo/sql_db\.py",\ line\ 101,\ in\ check
\ \ return\ f\(self,\ \*args,\ \*\*kwargs\)
\ File\ "/home/plus/odoo/odoo/sql_db\.py",\ line\ 301,\ in\ execute
\ \ res\ =\ self\._obj\.execute\(query,\ params\)
Exception
The\ above\ exception\ was\ the\ direct\ cause\ of\ the\ following\ exception:
Traceback\ \(most\ recent\ call\ last\):
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 641,\ in\ _handle_exception
\ \ return\ super\(JsonRequest,\ self\)\._handle_exception\(exception\)
\ File\ "/home/plus/odoo/odoo/http\.py",\ line\ 317,\ in\ _handle_exception
\ \ raise\ exception\.with_traceback\(None\)\ from\ new_cause
psycopg2\.errors\.UndefinedColumn:\ ERRORE:\ la\ colonna\ sc_personale_partecipazioni_agli_studi_generale\.id\ non\ esiste
LINE\ 2:\ \ \ \ \ \ \ SELECT\ min\("sc_personale_partecipazioni_agli_stu\.\.\.
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \^\ \ \ \ \ \ \
It's\ claiming\ that\ the\ table\ "sc_personale_partecipazioni_agli_studi_generale"\ has\ _no_\ "id"\ column
Here's\ my\ model\ definition
from\ odoo\ import\ fields,\ models,\ tools
class\ PersonalePartecipazioniAgliStudigenerale\(models\.Model\):
\ \ \ \ _name\ =\ 'sc_personale_partecipazioni_agli_studi_generale'
\ \ \ \ _auto\ =\ False
\ \ \ \ _description\ =\ 'Una\ vista\ unica\ su\ tutte\ le\ partecipazioni\ agli\ studi\ di\ tutto\ il\ personale'
\ \ \ \
\ \ \ \ id_professionista\ =\ fields\.Many2one\('sc\.personale',\ String="ID\ professionista",\ readonly=True\)
\ \ \ \ nome\ =\ fields\.Char\(String="Nome",\ readonly=True\)
\ \ \ \ cognome\ =\ fields\.Char\(String="Nome",\ readonly=True\)
\ \ \ \ profilo_professionale\ =\ fields\.Char\(String="Profilo\ Professionale",\ readonly=True\)
\ \ \ \ studio\ =\ fields\.Char\(String="Studio",\ readonly=True\)\
\ \ \ \ id_studio\ =\ fields\.Many2one\('res\.studio',\ String="ID\ studio",\ readonly=True\)
\ \ \ \ def\ init\(self\):
\ \ \ \ \ \ \ \ tools\.drop_view_if_exists\(self\.env\.cr,\ self\._table\)
\ \ \ \ \ \ \ \ query\ =\ """
\ \ \ \ \ \ \ \ CREATE\ OR\ REPLACE\ VIEW\ sc_personale_partecipazioni_agli_studi_generale\ AS\ \(
\ \ \ \ \ \ \ \ WITH\ partecipazioni\ AS\ \(
select\ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ studio\.id\ AS\ id_studio,\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ studio\.name\ as\ nome_studio,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_tecnici\.id\ AS\ id_partecipazione_tecnico,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_infermieri\.id\ AS\ id_partecipazione_infermiere,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_medici\.id\ AS\ id_partecipazione_medico,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_tecnici\.tecnico_id\ AS\ id_tecnico,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_infermieri\.infermiere_id\ AS\ id_infermiere,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ partecipazioni_medici\.medico_id\ AS\ id_medico
\
\ FROM\ res_studio\ AS\ studio
\
\ LEFT\ OUTER\ JOIN\ sc_personale_partecipazione_tecnici_allo_studio\ AS\ partecipazioni_tecnici\ ON\ studio\.id\ =\ partecipazioni_tecnici\.studio_id
\ LEFT\ OUTER\ JOIN\ sc_personale_partecipazione_infermieri_allo_studio\ AS\ partecipazioni_infermieri\ ON\ studio\.id\ =\ partecipazioni_infermieri\.studio_id
\ LEFT\ OUTER\ JOIN\ sc_personale_partecipazione_medici_allo_studio\ AS\ partecipazioni_medici\ ON\ studio\.id\ =\ partecipazioni_medici\.studio_id
\)
SELECT\ sc_personale\.id\ AS\ id_professionista,\ sc_personale\.name\ as\ nome,\ sc_personale\.cognome,\ sc_personale\.profilo_professionale,\ nome_studio\ as\ studio,\ id_studio
FROM\ sc_personale,\ partecipazioni
WHERE\ sc_personale\.id\ =\ partecipazioni\.id_tecnico\ OR\ sc_personale\.id\ =\ partecipazioni\.id_infermiere\ OR\ sc_personale\.id\ =\ partecipazioni\.id_medico
GROUP\ BY\ sc_personale\.id,\ partecipazioni\.id_studio,\ partecipazioni\.nome_studio
ORDER\ BY\ \ sc_personale\.profilo_professionale\)
\ \ \ \ \ \ \ \ """
\ \ \ \ \ \ \ \ self.env.cr.execute(query)
Hi Adriano Peluso,
If 'id_professionista' is unique field, you can change this column name to 'id'
or select new auto increment 'id' column like this:
Thanks!