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.

82 lines
3.0 KiB

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