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.

79 lines
2.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2017 Sunflower IT <http://sunflowerweb.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. class PartnerMergeTestCase(TransactionCase):
  6. """Tests for Partner Merge"""
  7. def setUp(self):
  8. super(PartnerMergeTestCase, self).setUp()
  9. self.partner = self.env['res.partner']
  10. self.merge_wizard = \
  11. self.env['base.partner.merge.automatic.wizard']
  12. self.donald_domain = [('name', '=', 'Donald Duck')]
  13. self.mickey_domain = [('name', '=', 'Mickey Mouse')]
  14. def _unlink_all(self):
  15. self.partner.search(self.donald_domain).unlink()
  16. self.partner.search(self.mickey_domain).unlink()
  17. def _count_donalds_mickeys(self, donalds, mickeys):
  18. self.assertEquals(
  19. len(self.partner.search(self.donald_domain)), donalds)
  20. self.assertEquals(
  21. len(self.partner.search(self.mickey_domain)), mickeys)
  22. def _create_duplicates(self, field1, value1, field2, values2):
  23. for value2 in values2:
  24. self.partner.create({
  25. field1: value1,
  26. field2: value2,
  27. })
  28. def test_10_name_merge(self):
  29. """ Merge users with duplicate names """
  30. self._unlink_all()
  31. self._create_duplicates(
  32. 'name', 'Donald Duck',
  33. 'email', ['donald@therp.nl', 'donald@sunflowerweb.nl'],
  34. )
  35. self._create_duplicates(
  36. 'name', 'Mickey Mouse',
  37. 'email', ['mickey@therp.nl', 'mickey@sunflowerweb.nl'],
  38. )
  39. self._count_donalds_mickeys(2, 2)
  40. # Merge all names that start with 'D',
  41. self.partner.deduplicate_on_fields(
  42. ['name'], domain=[('name', 'like', 'D%')],
  43. )
  44. self._count_donalds_mickeys(1, 2)
  45. def test_20_ref_merge(self):
  46. """ Merge users with duplicate references """
  47. self._unlink_all()
  48. self._create_duplicates(
  49. 'ref', 'DD123',
  50. 'name', ['Donald Duck', 'Mickey Mouse'],
  51. )
  52. # Merge on reference, leaving out guys that have no ref
  53. self.partner.deduplicate_on_fields(
  54. ['ref'], domain=[('ref', '=', 'DD123')],
  55. )
  56. # Test if only one remains after
  57. partners = self.partner.search([('ref', '=', 'DD123')])
  58. self.assertEquals(len(partners), 1)
  59. def test_30_ref_merge(self):
  60. """ Fringe case: three guys, two to merge """
  61. self._unlink_all()
  62. self._create_duplicates(
  63. 'ref', 'DD123',
  64. 'name', ['Donald Duck', 'Donald Duck', 'Mickey Mouse'],
  65. )
  66. self.partner.deduplicate_on_fields(
  67. ['ref'], domain=[('name', '=', 'Donald Duck')],
  68. )
  69. self._count_donalds_mickeys(1, 1)