Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

From old api to new api search and name_search functions

By
Ugne
on 6/28/16, 9:29 AM 580 views

Hello,

I have 2 functions from old api and I'm trying to convert them to new api.


def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):

    order='complete_name'

    for index, expr in enumerate(args):

        if expr[1] in ['like', 'ilike', 'not ilike', 'not like', '=like']:

            args[index][2] = re.sub(r"\s+", '%', expr[2])

    return super(stock_location, self).search(cr, uid, args, offset, limit, order, context, count)


def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=80):

    args.append(['complete_name', operator, name])

    ids = self.search(cr, uid, args, limit=limit, context=context)

    return self.name_get(cr, uid, ids)


As I understand I have to decorate it with @api.multi decorator. And whats with self environment? Also I have to use it?

The error is:


Odoo Server Error

Traceback (most recent call last):
  File "/opt/odoo/openerp/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/openerp/http.py", line 680, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/openerp/http.py", line 309, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/openerp/http.py", line 959, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/openerp/http.py", line 509, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 896, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/addons/web/controllers/main.py", line 884, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/api.py", line 381, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/del/addons/mik_stock/wizard/stock_operation.py", line 164, in do_transfer_and_view
    self.do_transfer()
  File "/opt/odoo/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/del/addons/mik_stock/wizard/stock_operation.py", line 107, in do_transfer
    self.picking_id.action_assign()
  File "/opt/odoo/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/api.py", line 574, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
  File "/opt/odoo/addons/stock/stock.py", line 1053, in action_assign
    self.pool.get('stock.move').action_assign(cr, uid, move_ids, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/stock/stock.py", line 2459, in action_assign
    quants = quant_obj.quants_get_preferred_domain(cr, uid, qty, move, domain=main_domain[move.id], preferred_domain_list=[], context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/del/addons/mik_stock/models/stock.py", line 383, in quants_get_preferred_domain
    return self.quants_get(cr, uid, qty, move, ops=ops, domain=domain, removal_strategy=removal_strategy, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/stock/stock.py", line 523, in quants_get
    return self.apply_removal_strategy(cr, uid, qty, move, ops=ops, domain=domain, removal_strategy=removal_strategy, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/stock/stock.py", line 528, in apply_removal_strategy
    return self._quants_get_order(cr, uid, quantity, move, ops=ops, domain=domain, orderby=order, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/stock/stock.py", line 706, in _quants_get_order
    quants = self.search(cr, uid, domain, order=orderby, limit=10, offset=offset, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/api.py", line 354, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/del/addons/mik_stock/models/stock.py", line 323, in search
    return super(stock_quant, self).search(args, offset, limit, order, count=count)
  File "/opt/odoo/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/api.py", line 490, in new_api
    result = method(self._model, cr, uid, *args, **old_kwargs)
  File "/opt/odoo/openerp/models.py", line 1658, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 4763, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 4534, in _where_calc
    e = expression.expression(cr, user, domain, self, context)
  File "/opt/odoo/openerp/osv/expression.py", line 644, in __init__
    self.parse(cr, uid, context=context)
  File "/opt/odoo/openerp/osv/expression.py", line 1043, in parse
    dom = HIERARCHY_FUNCS[operator](left, ids2, comodel, prefix=column._obj)
  File "/opt/odoo/openerp/osv/expression.py", line 725, in child_of_domain
    return [(left, 'in', left_model.search(cr, uid, doms, context=context))]
  File "/opt/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/del/addons/mok_stock/models/stock.py", line 280, in search
    if expr[1] in ['like', 'ilike', 'not ilike', 'not like', '=like']:
IndexError: string index out of range

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/28/16, 9:29 AM
Seen: 580 times
Last updated: 6/28/16, 9:44 AM