在 Odoo 和错误中自动填充网格
Auto Populate a Grid in Odoo and Error
当用户使用 One2many 关系字段创建新信息时,Odoo 会自动填充网格吗?
这是我的自动填充示例
def getCheckListId(self):
self.env.cr.execute("select 1 employee_id,1 PARAM1,1 PARAM2,1 PARAM3,1 PARAM3,1 PARAM4 from hr_employee_checklist ")
checklistTemplates = self.env.cr.fetchall()
return checklistTemplates
并且该函数将在 One2ManyFields 中用作默认值
employee_checklists = fields.One2many('hr.employee_checklist','employee_id', readonly=False,copy=False, default = getCheckListId)
但是我有一个错误
错误是
AttributeError: 'str' object has no attribute 'iteritems'
谁能帮我解决这个问题或其他在 Odoo 中填充网格的方法
一对多
一对多字段;此类字段的值是 comodel_name
中所有记录的 recordset
,因此字段 inverse_name
等于当前记录。
参数
- comodel_name -- 目标模型的名称(字符串)
- inverse_name -- comodel_name 中的逆 Many2one 字段的名称
(字符串)
- domain -- 一个可选的域,用于在客户端上设置候选值
边(域或字符串)
- context -- 在客户端使用的可选上下文
处理该字段(字典)
- auto_join -- 是否在搜索时生成 JOIN
字段(布尔值,默认为 False)
- limit -- 读取时使用的可选限制(整数)
因此,One2many 字段始终包含 commodel 的参考值,您只需要提供该关系字段的 id,其余部分将由 odoo 引擎自行维护。
@api.model
def getCheckListId(self):
return self.env['hr.employee.checklist'].search([]).ids
当用户使用 One2many 关系字段创建新信息时,Odoo 会自动填充网格吗?
这是我的自动填充示例
def getCheckListId(self):
self.env.cr.execute("select 1 employee_id,1 PARAM1,1 PARAM2,1 PARAM3,1 PARAM3,1 PARAM4 from hr_employee_checklist ")
checklistTemplates = self.env.cr.fetchall()
return checklistTemplates
并且该函数将在 One2ManyFields 中用作默认值
employee_checklists = fields.One2many('hr.employee_checklist','employee_id', readonly=False,copy=False, default = getCheckListId)
但是我有一个错误 错误是
AttributeError: 'str' object has no attribute 'iteritems'
谁能帮我解决这个问题或其他在 Odoo 中填充网格的方法
一对多
一对多字段;此类字段的值是 comodel_name
中所有记录的 recordset
,因此字段 inverse_name
等于当前记录。
参数
- comodel_name -- 目标模型的名称(字符串)
- inverse_name -- comodel_name 中的逆 Many2one 字段的名称 (字符串)
- domain -- 一个可选的域,用于在客户端上设置候选值 边(域或字符串)
- context -- 在客户端使用的可选上下文 处理该字段(字典)
- auto_join -- 是否在搜索时生成 JOIN 字段(布尔值,默认为 False)
- limit -- 读取时使用的可选限制(整数)
因此,One2many 字段始终包含 commodel 的参考值,您只需要提供该关系字段的 id,其余部分将由 odoo 引擎自行维护。
@api.model
def getCheckListId(self):
return self.env['hr.employee.checklist'].search([]).ids