Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

From old api to new api search and name_search functions

Subscribe

Get notified when there's activity on this post

This question has been flagged
ormpython2.7odooodoo9
1 Reply
7712 Views
Avatar
Ugne Sinkeviciene

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
0
Avatar
Discard
Avatar
Joël Gaujard @ Dépil Tech
Best Answer

I got pretty same problem. Did you succeed to solve your problem ?

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to bring products from opportunity to quotation
odoo odoo9
Avatar
0
Oct 23
3588
Different between create/new, write/update Solved
orm odoo
Avatar
Avatar
Avatar
Avatar
3
Sep 22
19176
Preview pdf,docs or other attachment file Solved
odoo odoo9
Avatar
Avatar
Avatar
Avatar
Avatar
4
Dec 21
34800
How to create a new decimal accuracy for subtotal in sale order odoo 9
python2.7 odoo9
Avatar
Avatar
1
Oct 21
5285
odoo 9 show user popups Solved
odoo odoo9
Avatar
Avatar
2
Dec 20
9758
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now