在odoo

时间:2015-07-31 05:45:21

标签: openerp odoo openerp-7 traceback

in odoo(fromerly openERP)我想自定义项目管理模块。

目前可以将任务分配给单个用户。型号代码是:

class task(osv.osv):
    _name = "project.task"
    _description = "Task"

    'user_id': fields.many2one('res.users', 'Assigned to', select=True, track_visibility='onchange'),

现在想要为多个用户分配任务。我修改了user_id字段,如下所示:

'user_id': fields.many2many('res.users', 'Assigned to', select=True, track_visibility='onchange'),

但它显示以下追溯:

Traceback (most recent call last):
  File "/home/hardik/odoo/odoo/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/home/hardik/odoo/odoo/addons/web/controllers/main.py", line 884, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "/home/hardik/odoo/odoo/addons/web/controllers/main.py", line 905, in do_search_read
    request.context)
  File "/home/hardik/odoo/odoo/openerp/http.py", line 908, in proxy
    result = meth(cr, request.uid, *args, **kw)
  File "/home/hardik/odoo/odoo/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/models.py", line 5146, in search_read
    result = self.read(cr, uid, record_ids, fields, context=read_ctx)
  File "/home/hardik/odoo/odoo/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/models.py", line 3141, in read
    result = BaseModel.read(records, fields, load=load)
  File "/home/hardik/odoo/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/models.py", line 3176, in read
    self._read_from_database(stored, inherited)
  File "/home/hardik/odoo/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/models.py", line 3354, in _read_from_database
    res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
  File "/home/hardik/odoo/odoo/openerp/osv/fields.py", line 1012, in get
    cr.execute(query, [tuple(ids),] + where_params)
  File "/home/hardik/odoo/odoo/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/home/hardik/odoo/odoo/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
ProgrammingError: syntax error at or near "to"
LINE 1: SELECT Assigned to.res_users_id, Assigned to.project_task_id...
                        ^

请指导我如何处理这个问题。提前谢谢

1 个答案:

答案 0 :(得分:0)

当我们创建 many2many 类型字段时,我们必须给出该表记录中存储的关系表的名称。在下面的示例中,' task_user_rel' 是一个关系表。

您可以尝试以下代码:

'user_ids': fields.many2many('res.users', 'task_user_rel', 'user_id', 'id', 'Assigned to', select=True, track_visibility='onchange'),

现在在xml端添加新的 user_ids 字段,隐藏/隐藏存在的 user_id 字段。