字段定义:
time_task_ids = fields.One2many('timesheet.timesheet','timesheet_id','Timesheet')
timesheet_id = fields.Many2one('timesheet.timesheet', 'Timesheet', compute='_compute_timesheet_id')
Transient_model_name = 'timesheet.data'
可能导致此问题的方法:
@api.onchange('created_by','created_date')
def on_change_created_by(self):
# list the task in timesheet based on user
task_ids = self.env['prj.task'].search([('task_assigned_to','=',self.created_by.id),
('state','=','ongoing'),('child_ids','=',False)])
task_list = []
for task in task_ids:
timesheet = self.env['timesheet.timesheet'].search([('task_ids', '=', task.id)])
tot_time = 0
for i in timesheet:
tot_time += i.duration
tot_duration = task.task_planned_hours - tot_time
vals = {
'task_ids': task.id,
'created_date': self.created_date,
'created_by': self.created_by.id,
'prj_project_id':task.prj_project_id.id,
'planned_hour': task.task_planned_hours,
'task_deadline_date': task.task_deadline_date,
'balance_hour': tot_duration,
'ref_parent_id': task.task_assigned_to.parent_id.id,
}
task_list.append((0, 0, vals))
self.time_task_ids = task_list
错误回溯:
2020-02-24 09:29:28,448 10954 ERROR new_db3 odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/home/guru/Documents/odoo-13/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/guru/Documents/odoo-13/odoo/http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/guru/Documents/odoo-13/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/home/guru/Documents/odoo-13/odoo/http.py", line 664, in dispatch
result = self._call_function(**self.params)
File "/home/guru/Documents/odoo-13/odoo/http.py", line 345, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/guru/Documents/odoo-13/odoo/service/model.py", line 93, in wrapper
return f(dbname, *args, **kwargs)
File "/home/guru/Documents/odoo-13/odoo/http.py", line 338, in checked_call
result = self.endpoint(*a, **kw)
File "/home/guru/Documents/odoo-13/odoo/http.py", line 910, in __call__
return self.method(*args, **kw)
File "/home/guru/Documents/odoo-13/odoo/http.py", line 510, in response_wrap
response = f(*args, **kw)
File "/home/guru/Documents/odoo-13/addons/web/controllers/main.py", line 1320, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/guru/Documents/odoo-13/addons/web/controllers/main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/guru/Documents/odoo-13/odoo/api.py", line 395, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/guru/Documents/odoo-13/odoo/api.py", line 382, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/guru/Documents/odoo-13/odoo/models.py", line 6056, in onchange
record._onchange_eval(name, field_onchange[name], result)
File "/home/guru/Documents/odoo-13/odoo/models.py", line 5857, in _onchange_eval
method_res = method(self)
File "/home/guru/Documents/odoo-13/addons/ajax_timesheet/wizard/wizard_timesheet.py", line 98, in on_change_created_by
self.time_task_ids = task_list
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 1068, in __set__
self.write(new_records, value)
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 2758, in write
return self.write_batch([(records, value)])
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 2782, in write_batch
return self.write_new(records_commands_list)
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 3002, in write_new
line[inverse] = record
File "/home/guru/Documents/odoo-13/odoo/models.py", line 5598, in __setitem__
return self._fields[key].__set__(self, value)
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 1068, in __set__
self.write(new_records, value)
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 2467, in write
cache_value = self.convert_to_cache(value, records)
File "/home/guru/Documents/odoo-13/odoo/fields.py", line 2400, in convert_to_cache
raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for timesheet.timesheet.timesheet_id: timesheet.data(<NewId 0x7fba579107b8>,)
给我一个解决这个错误的方法。one2many 中发生错误以列出分配