2

在 one2many 字段中创建新记录时遇到上述错误。

代码如下:

def _compute_timesheet_hour(self):
    for val in self:
        self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line 
        where project_id = %(project_id)s and employee_id = %(employee_id)s
        GROUP BY project_id, employee_id''', { 'project_id': val.project_id.id, 'employee_id': val.employee_id.id,})
        res = self._cr.fetchone()
        if res and res[2]:
            val.timesheet_hour = res[2]
        else:
            val.timesheet_hour = 0.0
4

1 回答 1

0

在创建时刻record.id,数据库中不存在 的值。为具有计算字段的模型创建记录时,记录集的记录将仅在内存中。那时,记录的 id 将是 type 的虚拟 id odoo.models.NewId

于 2021-03-14T10:24:32.947 回答