Skip to content

Commit

Permalink
[IMP] [8.0-i195-BR001028-T22321] Added code to search BR based on Nam…
Browse files Browse the repository at this point in the history
…e or Description in m2o fields (OCA#203)

* [IMP] Added code to search BR based on Name or Description in m2o fields.

* [IMP] Added UT to improved code coverage.

* [IMP] Modified the variables names as per GIT review.
  • Loading branch information
sudhir-serpentcs authored and Ruter Lv committed Mar 15, 2019
1 parent 3f46bb6 commit b0ad82a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions business_requirement/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ def name_get(self):
result.append((br.id, formatted_name))
return result

@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
"""
Search BR based on Name or Description
"""
# Make a search with default criteria
names = super(BusinessRequirement, self).name_search(
name=name, args=args, operator=operator, limit=limit)
# Make the other search
descriptions = []
if name:
domain = [('description', '=ilike', name + '%')]
descriptions = self.search(domain, limit=limit).name_get()
# Merge both results
return list(set(names) | set(descriptions))[:limit]

@api.multi
def action_button_confirm(self):
self.write({'state': 'confirmed'})
Expand Down
10 changes: 10 additions & 0 deletions business_requirement/tests/test_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ def test_action_button_done(self):
br = self.br.create(br_vals)
br.action_button_done()
self.assertEqual(br.state, 'done')

def test_br_name_search(self):
br_vals = {
'name': ' test',
'description': 'test',
'parent_id': False,
}
self.br.create(br_vals)
brs = self.br.name_search(name='test')
self.assertEqual(bool(brs), True)

0 comments on commit b0ad82a

Please sign in to comment.