marco garcia baturan
marco garcia baturan

Reputation: 11

Create button in form to create new record copy from the form in Odoo v8

I create module in Odoo v8.0. In the module I have a model (named cronograma) I create a button in the view form, who when clic try to create new record in the module, copy some specific fields and add this fields to new record.

This is the code of button:

    # 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

And this is the error mmessage:

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

Data about project:

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

Kind regards, Marco García Baturan.

Upvotes: 0

Views: 1283

Answers (1)

I don't really understand what you are trying to do with this code, but here are some problems:

  1. you cannot use the decorators @api.model and @api.multi at the same time. api.multi is for functions looping on a recordset, while api.model is for functions that does not depend on the recordset. these two cannot be used together.

  2. If this is a function for a button, what are the vals arguments? Nothing will be passed.

  3. You cannot index a record like this:

    record[...]

I don't really understand what that wants to be, but if you want to write to fields, you should use the record.write() method with a dictionary as an argument.

I suggest reading the documentation and the module creation how-to before trying to create modules utilising the orm api.

Upvotes: 2

Related Questions