You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

  1. # Copyright 2016 Daniel Reis
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase, at_install, post_install
  4. @at_install(False)
  5. @post_install(True)
  6. class NameSearchCase(TransactionCase):
  7. def setUp(self):
  8. super(NameSearchCase, self).setUp()
  9. phone_field = self.env.ref('base.field_res_partner_phone')
  10. model_partner = self.env.ref('base.model_res_partner')
  11. model_partner.name_search_ids = phone_field
  12. self.Partner = self.env['res.partner']
  13. self.partner1 = self.Partner.create(
  14. {'name': 'Luigi Verconti',
  15. 'customer': True,
  16. 'phone': '+351 555 777 333'})
  17. self.partner2 = self.Partner.create(
  18. {'name': 'Ken Shabby',
  19. 'customer': True,
  20. 'phone': '+351 555 333 777'})
  21. self.partner3 = self.Partner.create(
  22. {'name': 'Johann Gambolputty of Ulm',
  23. 'supplier': True,
  24. 'phone': '+351 777 333 555'})
  25. def test_RelevanceOrderedResults(self):
  26. """Return results ordered by relevance"""
  27. res = self.Partner.name_search('555 777')
  28. self.assertEqual(
  29. res[0][0], self.partner1.id,
  30. 'Match full string honoring spaces')
  31. self.assertEqual(
  32. res[1][0], self.partner2.id,
  33. 'Match words honoring order of appearance')
  34. self.assertEqual(
  35. res[2][0], self.partner3.id,
  36. 'Match all words, regardless of order of appearance')
  37. def test_NameSearchMustMatchAllWords(self):
  38. """Must Match All Words"""
  39. res = self.Partner.name_search('ulm 555 777')
  40. self.assertFalse(res)
  41. def test_MustHonorDomain(self):
  42. """Must also honor a provided Domain"""
  43. res = self.Partner.name_search('+351', args=[('supplier', '=', True)])
  44. gambulputty = self.partner3.id
  45. self.assertEqual(len(res), 1)
  46. self.assertEqual(res[0][0], gambulputty)