Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Add tests for base_location name_search #585

Merged
merged 4 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base_location/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Location management (aka Better ZIP)',
'version': '11.0.1.0.0',
'version': '11.0.1.0.1',
'depends': [
'base_address_city'
],
Expand Down
8 changes: 8 additions & 0 deletions base_location/models/better_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def name_get(self):
result.append((rec.id, ", ".join(name)))
return result

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
args = list(args or [])
args += ['|', ('city', operator, name),
'|', ('name', operator, name), ('code', operator, name)]
recs = self.search(args, limit=limit)
return recs.name_get()

@api.onchange('country_id')
def _onchange_country_id(self):
if self.state_id.country_id != self.country_id:
Expand Down
60 changes: 60 additions & 0 deletions base_location/tests/test_base_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,66 @@ def test_display_name(self):
).name
)

def test_name_search___can_find_using_city_name_or_zip_or_code(self):
barcelona_data = {
'city_id': self.city_bcn.id,
'city': self.city_bcn.name,
'name': '444',
'code': 'BA',
'state_id': self.state_bcn.id,
'country_id': self.ref('base.es'),
}
madrid_data = {
'city_id': self.city_madrid.id,
'city': self.city_madrid.name,
'name': '555',
'code': 'MD',
'state_id': self.state_madrid.id,
'country_id': self.ref('base.es'),
}
lausanne_data = {
'city_id': self.city_lausanne.id,
'city': self.city_lausanne.name,
'name': '666',
'code': 'LA',
'state_id': self.state_vd.id,
'country_id': self.ref('base.ch'),
}

barcelona = self.env['res.better.zip'].create(barcelona_data)
madrid = self.env['res.better.zip'].create(madrid_data)
lausanne = self.env['res.better.zip'].create(lausanne_data)

found_recs = self.env['res.better.zip'].name_search(name='444')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], barcelona.id)
found_recs = self.env['res.better.zip'].name_search(name='Barcelona')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], barcelona.id)
found_recs = self.env['res.better.zip'].name_search(name='BA')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], barcelona.id)

found_recs = self.env['res.better.zip'].name_search(name='555')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], madrid.id)
found_recs = self.env['res.better.zip'].name_search(name='Madrid')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], madrid.id)
found_recs = self.env['res.better.zip'].name_search(name='MD')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], madrid.id)

found_recs = self.env['res.better.zip'].name_search(name='666')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], lausanne.id)
found_recs = self.env['res.better.zip'].name_search(name='Lausanne')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], lausanne.id)
found_recs = self.env['res.better.zip'].name_search(name='LA')
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], lausanne.id)

def setUp(self):
super(TestBaseLocation, self).setUp()
self.state_vd = self.env['res.country.state'].create({
Expand Down