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.

47 lines
1.8 KiB

  1. # Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
  2. # Copyright 2016 Tecnativa S.L. - Vicent Cubells
  3. # Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo.exceptions import UserError, ValidationError
  6. from odoo.tests import common
  7. class TestResPartnerIndustry(common.SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestResPartnerIndustry, cls).setUpClass()
  11. cls.industry_model = cls.env["res.partner.industry"]
  12. cls.industry_main = cls.industry_model.create({"name": "Test"})
  13. cls.industry_child = cls.industry_model.create(
  14. {"name": "Test child", "parent_id": cls.industry_main.id}
  15. )
  16. def test_check_industries(self):
  17. with self.assertRaises(ValidationError):
  18. self.env["res.partner"].create(
  19. {
  20. "name": "Test",
  21. "industry_id": self.industry_main.id,
  22. "secondary_industry_ids": [(4, self.industry_main.id)],
  23. }
  24. )
  25. def test_check_copy(self):
  26. industry_copy = self.industry_child.copy()
  27. self.assertEqual(industry_copy.name, "Test child 2")
  28. def test_check_uniq_name(self):
  29. with self.assertRaises(ValidationError):
  30. self.industry_model.create({"name": "Test"})
  31. def test_check_recursion(self):
  32. with self.assertRaises(UserError):
  33. self.industry_main.parent_id = self.industry_child.id
  34. with self.assertRaises(ValidationError) as e:
  35. self.industry_main._check_parent_id()
  36. error_message = "Error! You cannot create recursive industries."
  37. self.assertEqual(e.exception.args[0], error_message)
  38. def test_name(self):
  39. self.assertEqual(self.industry_child.display_name, "Test / Test child")