Skip to content

Commit

Permalink
[FIX] *: override _search instead of search where it makes sense
Browse files Browse the repository at this point in the history
This fixes potential quirks, as the conversion of domains now uses `_search`
instead of `search`.
  • Loading branch information
rco-odoo committed Aug 16, 2017
1 parent 38f7531 commit c497db2
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions addons/account/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def name_search(self, name, args=None, operator='ilike', limit=80):
return taxes.name_get()

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
context = self._context or {}

if context.get('type'):
Expand All @@ -732,7 +732,7 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
if journal.type in ('sale', 'purchase'):
args += [('type_tax_use', '=', journal.type)]

return super(AccountTax, self).search(args, offset, limit, order, count=count)
return super(AccountTax, self)._search(args, offset, limit, order, count=count, access_rights_uid=access_rights_uid)

@api.onchange('amount')
def onchange_amount(self):
Expand Down
14 changes: 7 additions & 7 deletions addons/calendar/models/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def unlink(self, can_be_deleted=True):
return result

@api.model
def search(self, args, offset=0, limit=0, order=None, count=False):
def _search(self, args, offset=0, limit=0, order=None, count=False, access_rights_uid=None):
if self._context.get('mymeetings'):
args += [('partner_ids', 'in', self.env.user.partner_id.ids)]

Expand All @@ -1559,7 +1559,7 @@ def search(self, args, offset=0, limit=0, order=None, count=False):
new_args.append(new_arg)

if not self._context.get('virtual_id', True):
return super(Meeting, self).search(new_args, offset=offset, limit=limit, order=order, count=count)
return super(Meeting, self)._search(new_args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

if any(arg[0] == 'start' for arg in args) and \
not any(arg[0] in ('stop', 'final_date') for arg in args):
Expand All @@ -1574,13 +1574,13 @@ def search(self, args, offset=0, limit=0, order=None, count=False):
new_args.append(new_arg)

# offset, limit, order and count must be treated separately as we may need to deal with virtual ids
events = super(Meeting, self).search(new_args, offset=0, limit=0, order=None, count=False)
events = self.browse(events.get_recurrent_ids(args, order=order))
ids = super(Meeting, self)._search(new_args, offset=0, limit=0, order=None, count=False, access_rights_uid=access_rights_uid)
ids = self.browse(ids).get_recurrent_ids(args, order=order)
if count:
return len(events)
return len(ids)
elif limit:
return events[offset: offset + limit]
return events
return ids[offset: offset + limit]
return ids

@api.multi
def copy(self, default=None):
Expand Down
4 changes: 2 additions & 2 deletions addons/calendar/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Attachment(models.Model):
_inherit = "ir.attachment"

@api.model
def search(self, args, offset=0, limit=0, order=None, count=False):
def _search(self, args, offset=0, limit=0, order=None, count=False, access_rights_uid=None):
""" Convert the search on real ids in the case it was asked on virtual ids, then call super() """
args = list(args)
if any([leaf for leaf in args if leaf[0] == "res_model" and leaf[2] == 'calendar.event']):
for index in range(len(args)):
if args[index][0] == "res_id" and isinstance(args[index][2], basestring):
args[index] = (args[index][0], args[index][1], get_real_ids(args[index][2]))
return super(Attachment, self).search(args, offset=offset, limit=limit, order=order, count=count)
return super(Attachment, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

@api.multi
def write(self, vals):
Expand Down
4 changes: 2 additions & 2 deletions addons/calendar/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Message(models.Model):
_inherit = "mail.message"

@api.model
def search(self, args, offset=0, limit=0, order=None, count=False):
def _search(self, args, offset=0, limit=0, order=None, count=False, access_rights_uid=None):
""" Convert the search on real ids in the case it was asked on virtual ids, then call super() """
args = list(args)
for index in range(len(args)):
Expand All @@ -20,7 +20,7 @@ def search(self, args, offset=0, limit=0, order=None, count=False):
args[index] = (args[index][0], args[index][1], get_real_ids(args[index][2]))
elif isinstance(args[index][2], list):
args[index] = (args[index][0], args[index][1], [get_real_ids(x) for x in args[index][2]])
return super(Message, self).search(args, offset=offset, limit=limit, order=order, count=count)
return super(Message, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

@api.model
def _find_allowed_model_wise(self, doc_model, doc_dict):
Expand Down
4 changes: 2 additions & 2 deletions addons/marketing_campaign/models/ir_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
model_id = self.env.context.get('object_id')
if model_id:
model = self.env['ir.model'].browse(model_id).model
args.append(('model', '=', model))
return super(IrActionsReport, self).search(args, offset=offset, limit=limit, order=order, count=count)
return super(IrActionsReport, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)
4 changes: 2 additions & 2 deletions addons/marketing_campaign/models/marketing_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ class MarketingCampaignActivity(models.Model):
"cancelled instead of being deleted.")

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
if 'segment_id' in self.env.context:
return self.env['marketing.campaign.segment'].browse(self.env.context['segment_id']).campaign_id.activity_ids
return super(MarketingCampaignActivity, self).search(args, offset, limit, order, count)
return super(MarketingCampaignActivity, self)._search(args, offset, limit, order, count, access_rights_uid=access_rights_uid)

@api.multi
def _process_wi_email(self, workitem):
Expand Down
4 changes: 2 additions & 2 deletions addons/point_of_sale/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class AccountJournal(models.Model):
"the closing of his session saying that he needs to contact his manager.")

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
session_id = self.env.context.get('pos_session_id', False)
if session_id:
session = self.env['pos.session'].browse(session_id)
if session:
args += [('id', 'in', session.config_id.journal_ids.ids)]
return super(AccountJournal, self).search(args=args, offset=offset, limit=limit, order=order, count=count)
return super(AccountJournal, self)._search(args=args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

@api.onchange('type')
def onchange_type(self):
Expand Down
4 changes: 2 additions & 2 deletions addons/product/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ def copy(self, default=None):
return super(ProductProduct, self).copy(default=default)

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
# TDE FIXME: strange
if self._context.get('search_default_categ_id'):
args.append((('categ_id', 'child_of', self._context['search_default_categ_id'])))
return super(ProductProduct, self).search(args, offset=offset, limit=limit, order=order, count=count)
return super(ProductProduct, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

@api.multi
def name_get(self):
Expand Down
14 changes: 7 additions & 7 deletions odoo/addons/base/ir/ir_ui_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ def _filter_visible_menus(self):
return self.filtered(lambda menu: menu.id in visible_ids)

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
menus = super(IrUiMenu, self).search(args, offset=0, limit=None, order=order, count=False)
if menus:
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
ids = super(IrUiMenu, self)._search(args, offset=0, limit=None, order=order, count=False, access_rights_uid=access_rights_uid)
if ids:
# menu filtering is done only on main menu tree, not other menu lists
if not self._context.get('ir.ui.menu.full_list'):
menus = menus._filter_visible_menus()
ids = self.browse(ids)._filter_visible_menus().ids
if offset:
menus = menus[offset:]
ids = ids[offset:]
if limit:
menus = menus[:limit]
return len(menus) if count else menus
ids = ids[:limit]
return len(ids) if count else ids

@api.multi
def name_get(self):
Expand Down
4 changes: 2 additions & 2 deletions odoo/addons/base/res/res_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _compute_acc_type(self):
bank.acc_type = 'bank'

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
pos = 0
while pos < len(args):
if args[pos][0] == 'acc_number':
Expand All @@ -96,4 +96,4 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
value = '%' + value + '%'
args[pos] = ('sanitized_acc_number', op, value)
pos += 1
return super(ResPartnerBank, self).search(args, offset, limit, order, count=count)
return super(ResPartnerBank, self)._search(args, offset, limit, order, count=count, access_rights_uid=access_rights_uid)
6 changes: 3 additions & 3 deletions odoo/addons/base/res/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ def _search_full_name(self, operator, operand):
return where

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
# add explicit ordering if search is sorted on full_name
if order and order.startswith('full_name'):
groups = super(Groups, self).search(args)
groups = self.browse(super(Groups, self)._search(args, access_rights_uid=access_rights_uid))
groups = groups.sorted('full_name', reverse=order.endswith('DESC'))
groups = groups[offset:offset+limit] if limit else groups[offset:]
return len(groups) if count else groups.ids
return super(Groups, self).search(args, offset=offset, limit=limit, order=order, count=count)
return super(Groups, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

@api.multi
def copy(self, default=None):
Expand Down

0 comments on commit c497db2

Please sign in to comment.