删除记录
可以通过向unlink()提供记录的id来批量删除记录。
models.execute_kw(db, uid, password, 'res.partner', 'unlink', [[id]])
#检查已删除的记录是否仍在数据库中
models.execute_kw(db, uid, password, 'res.partner', 'search', [[['id', '=', id]]])
检查和反省
虽然我们以前使用fields_get()来查询模型,并且从一开始就使用任意模型,但Odoo将大多数模型元数据存储在一些元模型中,这些元模型允许在XML-RPC上查询系统并更改模型和字段(有一些限制)。
ir.model
通过其各个字段提供有关Odoo模型的信息。
name
模型的可读描述
model
系统中每个模型的名称
state
无论模型是在Python代码中生成的(基本)还是通过创建ir.model记录生成的(手动)
field_id
通过One2many到ir.model.fields的模型字段列表
view_id
One2many到为模型定义的视图
access_ids
One2many 与模型上设置的访问权限的关系
ir.model可以用于
在系统中查询已安装的模型(作为对模型进行操作或探索系统内容的先决条件)。
获取有关特定模型的信息(通常通过列出与之相关的字段)。
通过RPC动态创建新模型。
注意:
自定义模型名称必须以x_开头。
必须提供状态并将其设置为手动,否则将不会加载模型。
无法向自定义模型中添加新方法,只能添加字段。
models.execute_kw(db, uid, password, 'ir.model', 'create', [{
'name': "Custom Model",
'model': "x_custom_model",
'state': 'manual',
}])
models.execute_kw(db, uid, password, 'x_custom_model', 'fields_get', [], {'attributes': ['string', 'help', 'type']})
返回:
{
"create_uid": {
"type": "many2one",
"string": "Created by"
},
"create_date": {
"type": "datetime",
"string": "Created on"
},
"__last_update": {
"type": "datetime",
"string": "Last Modified on"
},
"write_uid": {
"type": "many2one",
"string": "Last Updated by"
},
"write_date": {
"type": "datetime",
"string": "Last Updated on"
},
"display_name": {
"type": "char",
"string": "Display Name"
},
"id": {
"type": "integer",
"string": "Id"
}
}