在表单中创建按钮以从Odoo v8中的表单创建新的记录副本

时间:2017-08-21 10:45:17

标签: python-2.7 ubuntu odoo-8

我在Odoo v8.0中创建模块。在模块中我有一个模型(命名为cronograma) 我在视图表单中创建了一个按钮,当clic尝试在模块中创建新记录时,复制一些特定字段并将此字段添加到新记录中。

这是按钮的代码:

    # code of botton who invoke more date therapy
@api.model
@api.multi
def generate_record_name(self, values):
    # Override the original create function for the cronograma.cronograma model
    record = super(cronograma, self).create(values)
    # values to pass for record in new add to database
    record['paciente_id',
           'Nombre',
           'start_date',
           'start_time',
           'duration',
           'end_date',
           'Neuro',
           'Fisio',
           'Logo',
           'TS',
           'TO',] = True
    # return record whit the same form
    return record

这就是错误消息:

Odoo Server Error

Traceback (most recent call last):
  File "/opt/odoo/odoo-server/openerp/http.py", line 546, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-server/openerp/http.py", line 583, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-server/openerp/http.py", line 319, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/http.py", line 316, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 812, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 412, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 371, in old_api
    recs = self.browse(cr, uid, [], context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/models.py", line 5282, in browse
    return self._browse(Environment(cr, uid, context or {}), ids)
  File "/opt/odoo/odoo-server/openerp/api.py", line 769, in __new__
    self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context))
TypeError: cannot convert dictionary update sequence element #0 to a sequence

有关项目的数据:

S.O: Ubuntu 14.04
Virtualization: Yes
ERP: Odoo v8.0
Language: Python 2.7

亲切的问候, MarcoGarcíaBaturan。

1 个答案:

答案 0 :(得分:1)

我真的不明白你要对这段代码做什么,但这里有一些问题:

  1. 您无法同时使用装饰器@api.model@api.multi。 api.multi用于在记录集上循环的函数,而api.model用于不依赖于记录集的函数。这两者不能一起使用。

  2. 如果这是一个按钮的函数,那么vals参数是什么?什么都不会过去。

  3. 您无法为此记录编制索引:

    记录[...]

  4. 我真的不明白它想成为什么,但是如果你想写字段,你应该使用record.write()方法和字典作为参数。

    我建议在尝试使用orm api创建模块之前阅读documentation和模块创建方法。