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.

76 lines
3.0 KiB

  1. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. from odoo.tools.safe_eval import safe_eval
  5. class TestDeduplicateFilter(common.TransactionCase):
  6. def setUp(self):
  7. super(TestDeduplicateFilter, self).setUp()
  8. self.partner_1 = self.env['res.partner'].create({
  9. 'name': 'Partner 1',
  10. 'email': 'partner1@example.org',
  11. 'is_company': True,
  12. 'parent_id': False,
  13. })
  14. self.partner_1.copy()
  15. self.partner_2 = self.env['res.partner'].create({
  16. 'name': 'Partner 2',
  17. 'email': 'partner2@example.org',
  18. 'is_company': False,
  19. 'parent_id': self.partner_1.id,
  20. })
  21. self.partner_2.copy()
  22. self.partner_3 = self.env['res.partner'].create({
  23. 'name': 'Partner 3',
  24. 'email': 'partner3@example.org',
  25. 'is_company': False,
  26. 'parent_id': False,
  27. })
  28. self.partner_3.copy()
  29. self.wizard = self.env['base.partner.merge.automatic.wizard'].create({
  30. 'group_by_email': True,
  31. })
  32. def test_deduplicate_exclude_is_company(self):
  33. self.wizard.exclude_is_company = True
  34. self.wizard.action_start_manual_process()
  35. matched_founds = 0
  36. for line in self.wizard.line_ids:
  37. match_ids = safe_eval(line.aggr_ids)
  38. if self.partner_1.id in match_ids:
  39. self.assertTrue(False, 'Partner with is company not excluded')
  40. if self.partner_2.id in match_ids:
  41. matched_founds += 1
  42. if self.partner_3.id in match_ids:
  43. matched_founds += 1
  44. self.assertEqual(matched_founds, 2)
  45. def test_deduplicate_exclude_not_parent(self):
  46. self.wizard.exclude_not_parent = True
  47. self.wizard.action_start_manual_process()
  48. matched_founds = 0
  49. for line in self.wizard.line_ids:
  50. match_ids = safe_eval(line.aggr_ids)
  51. if self.partner_1.id in match_ids:
  52. self.assertTrue(False, 'Partner without parent not excluded')
  53. if self.partner_3.id in match_ids:
  54. self.assertTrue(False, 'Partner without parent not excluded')
  55. if self.partner_2.id in match_ids:
  56. matched_founds += 1
  57. self.assertEqual(matched_founds, 1)
  58. def test_deduplicate_exclude_parent(self):
  59. self.wizard.exclude_parent = True
  60. self.wizard.action_start_manual_process()
  61. matched_founds = 0
  62. for line in self.wizard.line_ids:
  63. match_ids = safe_eval(line.aggr_ids)
  64. if self.partner_2.id in match_ids:
  65. self.assertTrue(False, 'Partner with parent not excluded')
  66. if self.partner_1.id in match_ids:
  67. matched_founds += 1
  68. if self.partner_3.id in match_ids:
  69. matched_founds += 1
  70. self.assertEqual(matched_founds, 2)