psycopg2.ProgrammingError: can't adapt type 'NewId' in odoo 14

Viewed 852

Getting above error creating new record in one2many field.

code is below:

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
1 Answers

At create moment the value of record.id doesn't exist in database. When creating a record for a model with computed fields, the records of the record-set will be in memory only. At that time the id of the record will be dummy ids of type odoo.models.NewId.

Related