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.

68 lines
2.5 KiB

  1. # Copyright 2021 Patrick Wilson <pwilson@opensourceintegrators.com>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo.exceptions import ValidationError
  4. from odoo.tests import common, tagged
  5. @tagged("-at_install", "post_install")
  6. class TestPartnerTierValidation(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super().setUpClass()
  10. # Get res partner model
  11. cls.partner_model = cls.env.ref("base.model_res_partner")
  12. # Create users
  13. group_ids = cls.env.ref("base.group_system").ids
  14. group_ids.append(cls.env.ref("base.group_partner_manager").id)
  15. cls.test_user_1 = cls.env["res.users"].create(
  16. {
  17. "name": "John",
  18. "login": "test1",
  19. "groups_id": [(6, 0, group_ids)],
  20. "email": "test@examlple.com",
  21. }
  22. )
  23. # Create tier definitions:
  24. cls.tier_def_obj = cls.env["tier.definition"]
  25. cls.tier_def_obj.create(
  26. {
  27. "model_id": cls.partner_model.id,
  28. "review_type": "individual",
  29. "reviewer_id": cls.test_user_1.id,
  30. "definition_domain": "['&',('is_company','=',True),'|', \
  31. ('active','=',True),('active','=',False)]",
  32. }
  33. )
  34. def test_tier_validation_model_name(self):
  35. self.assertIn(
  36. "res.partner", self.tier_def_obj._get_tier_validation_model_names()
  37. )
  38. def test_validation_res_partner(self):
  39. company = self.env["res.partner"].create(
  40. {"name": "Company for test", "company_type": "company"}
  41. )
  42. # Since company need validation, it should be inactive
  43. self.assertEqual(company.active, False)
  44. # Assert an error shows if trying to make it active
  45. with self.assertRaises(ValidationError):
  46. company.write({"state": "confirmed"})
  47. # Request and validate partner
  48. company.request_validation()
  49. company.with_user(self.test_user_1).validate_tier()
  50. company.with_user(self.test_user_1).write({"state": "confirmed"})
  51. self.assertEqual(company.state, "confirmed")
  52. # Change company type to retrigger validation
  53. company.write({"company_type": "person", "is_company": False})
  54. self.assertEqual(company.state, "draft")
  55. # Test partner creation that doesn't need validation
  56. customer = self.env["res.partner"].create({"name": "Partner for test"})
  57. self.assertEqual(customer.active, True)