Community: Framework mailing list archives

expert-framework@mail.odoo.com

V8 api broken on many2many record?

by
Maxim Litnitskiy
- 09/06/2014 06:04:38
I am using 8.0 branch.
Here is the code that breaks.

class dialplan(models.Model):
    _name = 'astpbx.dialplan'
    
    exten_ids = fields.Many2many('astpbx.exten', 'astpbx_dialplan_exten', string='Extensions')

This works:

        # Old API
        DP = self.pool.get('astpbx.dialplan')
        dp_ids = DP.search(self.env.cr, self.env.uid, []) 
        DPs = DP.browse(self.env.cr, self.env.uid, dp_ids)
        for dialplan in DPs:
            print dialplan.exten_ids

astpbx.exten(12, 14)
astpbx.exten(16, 12, 17, 19, 14)

This does not work:
        
        # New API, astpbx.dialplan method
        for dialplan in self.browse(self.search([])):
            print dialplan.exten_ids

Traceback:

2014-09-06 09:59:55,657 11980 WARNING odoo_test8 openerp.models: Comparing apples and oranges: astpbx.dialplan(1,) == 1
2014-09-06 09:59:55,657 11980 WARNING odoo_test8 openerp.models: Comparing apples and oranges: astpbx.dialplan(1,) == 2
2014-09-06 09:59:55,658 11980 ERROR odoo_test8 openerp.sql_db: Programming error: can't adapt type 'astpbx.dialplan', in query  SELECT astpbx_dialplan."id" FROM "astpbx_dialplan"
                    WHERE astpbx_dialplan.id IN %s AND (TRUE)
                    ORDER BY name

2014-09-06 09:59:55,658 11980 ERROR odoo_test8 openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/odoo/openerp/http.py", line 496, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/openerp/http.py", line 513, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/openerp/http.py", line 279, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/http.py", line 276, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/openerp/http.py", line 723, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/openerp/http.py", line 372, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo/addons/web/controllers/main.py", line 941, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/odoo/addons/web/controllers/main.py", line 933, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/addons/base_action_rule/base_action_rule.py", line 223, in write
    action_model._process(cr, uid, action, post_ids, context=context)
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/addons/base_action_rule/base_action_rule.py", line 151, in _process
    action_server_obj.run(cr, uid, server_action_ids, context=ctx)
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/addons/base/ir/ir_actions.py", line 1011, in run
    res = func(cr, uid, action, eval_context=eval_context, context=run_context)
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/addons/website/models/ir_actions.py", line 62, in run_action_code_multi
    res = super(actions_server, self).run_action_code_multi(cr, uid, action, eval_context, context)
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/addons/base/ir/ir_actions.py", line 848, in run_action_code_multi
  File "/opt/odoo/odoo/openerp/addons/base/ir/ir_actions.py", line 848, in run_action_code_multi
    eval(action.code.strip(), eval_context, mode="exec", nocopy=True)  # nocopy allows to return 'action'
  File "/opt/odoo/odoo/openerp/tools/safe_eval.py", line 312, in safe_eval
    return eval(c, globals_dict, locals_dict)
  File "", line 11, in <module>
  File "/opt/odoo/odoo/openerp/api.py", line 235, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/api.py", line 330, in old_api
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/myaddons/astpbx_base/models/dialplan.py", line 103, in generate_config
    res += self.gen_dialplan()
  File "/opt/odoo/odoo/openerp/api.py", line 233, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/myaddons/astpbx_base/models/dialplan.py", line 87, in gen_dialplan
    print dialplan.exten_ids 
  File "/opt/odoo/odoo/openerp/fields.py", line 711, in __get__
    self.determine_value(record)
  File "/opt/odoo/odoo/openerp/fields.py", line 802, in determine_value
    record._prefetch_field(self)
  File "/opt/odoo/odoo/openerp/api.py", line 233, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/models.py", line 3170, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/opt/odoo/odoo/openerp/api.py", line 233, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/models.py", line 3120, in read
    self._read_from_database(stored)
  File "/opt/odoo/odoo/openerp/api.py", line 233, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/models.py", line 3227, in _read_from_database
    cr.execute(query, [tuple(sub_ids)] + rule_params)
  File "/opt/odoo/odoo/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/odoo/odoo/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
  File "/opt/odoo/env/local/lib/python2.7/site-packages/psycopg2/extensions.py", line 129, in getquoted
    pobjs = [adapt(o) for o in self._seq]
ValueError: "can't adapt type 'astpbx.dialplan'" while evaluating
ValueError: "can't adapt type 'astpbx.dialplan'" while evaluating
u'# You can use the following variables:\n#  - self: ORM model of the record on which the action is triggered\n#  - object: Record on which the action is triggered if there is one, otherwise None\n#  - pool: ORM model pool (i.e. self.pool)\n#  - cr: database cursor\n#  - uid: current user id\n#  - context: current context\n#  - time: Python time module\n#  - workflow: Workflow engine\n# If you plan to return an action, assign: action = {...}\nself.generate_config(cr, uid, context=context)'
2014-09-06 09:59:55,668 11980 INFO odoo_test8 werkzeug: 127.0.0.1 - - [06/Sep/2014 09:59:55] "POST /web/dataset/call_kw/astpbx.dialplan/write HTTP/1.1" 200 -