-
Notifications
You must be signed in to change notification settings - Fork 8
cls._get_fields2
suxuelengyin edited this page Dec 26, 2018
·
12 revisions
cls._get_fields2(feilds)
入口:
- 参数 fields
- cls._fields
- cls._env
出口:
- 返回一个List
- cls._env 中 会出现新模型
fields 示例:
fields = {
name: null,
m2o_field1: null,
m2o_field2: {name: null },
m2o_field3: {name: null, m2o_field31: null, o2m_field31: null },
m2o_field4: {name: null, m2o_field41: {name, null}, o2m_field41: {name: null} },
o2m_field1: null,
o2m_field2: {name: null },
o2m_field3: {name: null, m2o_field31: null, o2m_field31: null },
o2m_field4: {name: null, m2o_field41: {name, null}, o2m_field41: {name: null} },
}
cls._fields 示例
{
name: {type: 'char'},
m2o_field: {type: 'many2one', relation: 'ref_model'},
o2m_field: {type: 'one2many', relation: 'child_model'},
}
cls._env 示例:
{
'model1': Obejct,
'model2': Obejct,
'model3': Obejct
}
返回值示例:
['name', 'm2o_field1', ['m2o_field2',[ 'name' ] ], 'o2m_field1', ['o2m_field2',['name']] ]
测试基础:
const models = {
'res.users': ['login', 'name', 'partner_id', 'company_id', 'category_id','email'],
'res.partner': [
'name',
'email',
'title',
'user_id',
'company_id',
'category_id',
],
'res.partner.title': ['name', 'shortcut'],
'res.company': ['name', 'email'],
'res.country': ['name'],
'res.partner.category':['name','cate']
};
const odoo = get_odoo();
await odoo.login({ login: 'admin', password: '123' });
const Partner = odoo.env('res.partner');
const fields = {//输入
ref: null,
title: { name: null },
};
const fields2 = await Partner._get_fields2(fields);//输出
测试涵盖情况:
-
字段在 fields, cls._fields 不一致:
- 以cls._fields为准,最终的字段,一定与它完全一致
//输入
const fields = {
ref: null,//不存在的字段
title: { name: null },//m2o字段
category_id: {name:null},//m2m字段
}
//输出
fields2 = [
'name',
'email',
['title', ['name', 'shortcut']],
'user_id',
'company_id',
['category_id',['name','cate']]
]
- m2o字段 为null 或 不为空:
为null,返回'm2o_fields'
//输入
const fields = {
ref: null,//不存在的字段
title: null,//m2o字段
category_id: null,//m2m字段
}
//输出
fields2=[
'name',
'email',
'title',
'user_id',
'company_id',
'category_id',
]
不为null,返回['m2o_fields',['name',...]]
同第一段代码
-
o2m字段 为null 或 不为空:
- 同上
-
cls._env中 已定义 或 未定义模型:
- 已经定义就会直接加载该模型,未定义则重新调用
modelCreator
创建新模型
- 已经定义就会直接加载该模型,未定义则重新调用