Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
5279 Näkymät

Hello Community

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
Avatar
Hylkää
Paras vastaus

Hi,

This issue may be with the data type being passed as an argument in the SQL query.
Try this,

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 = %s AND employee_id = %s
GROUP BY project_id, employee_id''', (val.project_id.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

The SQL query passes a tuple of parameters (val.project_id.id, val.employee_id.id,) using placeholders of the form '%s'. This should help resolve the issue you're facing with adapting the argument types correctly

Regards

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
maalisk. 23
2447
0
lokak. 15
4738
2
heinäk. 24
7688
1
toukok. 24
3158
3
helmik. 25
3555