侧边栏壁纸
博主头像
EinTao博主等级

昨天再好,也走不回去;明天再难,也要抬脚继续。

  • 累计撰写 32 篇文章
  • 累计创建 3 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

odoo根据ir_field查询模型下的所有字段

EinTao
2022-11-27 / 0 评论 / 0 点赞 / 32 阅读 / 354 字
select REPLACE(model.model, '.', '_') as "表名", 
(select mot.value
                         from ir_translation mot 
                         where mot.res_id = model.id
                         and mot.name = 'ir.model,name'
                         and mot.state = 'translated'
                         and mot.lang = 'zh_CN'
                         and mot.value is not null
                         limit 1) as "表描述",
                         field.name as "字段名称",
                         coalesce((select fit.value
                         from ir_translation fit 
                         where 1 = 1
                         and name = 'ir.model.fields,field_description'
                         and fit.res_id = field.id
                         and fit.state = 'translated'
                         and fit.lang = 'zh_CN'
                         and fit.type = 'model'
                         and fit.value is not null
                         limit 1),field.field_description) as "字段描述",
                         case 
                         when field.ttype in ('many2one', 'integer')  then 'int4'
                         when field.ttype in ('char', 'selection') then 'varchar'
                         when field.ttype = 'date' then 'timestamp'
                         when field.ttype = 'boolean' then 'bool'
                         when field.ttype = 'float' then 'float8'
                         else field.ttype
                         end 类型,
                         case 
                         when field.required = True then '是'
                         else '否' 
                         end 必输,
                         REPLACE(relation, '.', '_') 关联表,
                         case
                         when field.ttype = 'many2one' then 'FK'
                         when field.name = 'id' then 'PK'
                         end 备注
from ir_model model
join ir_model_fields field on model.id = field.model_id
where 1 = 1
and field.name not in ('create_date', 'create_uid', 'write_date', 'write_uid', '__last_update','field_show')
and field.ttype not in ('many2many', 'one2many')
and model.model like 'product.product'


and model.model not like '%report%'
and model.model not like '%wizard%'
and model.model not like 'hrp.base%'
order by model.model, case  when field.name = 'id' then 1 else 2 end
0

评论区