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.

89 lines
3.5 KiB

  1. from odoo.tests import common
  2. class TestPartnerAffiliate(common.TransactionCase):
  3. def setUp(self):
  4. super(TestPartnerAffiliate, self).setUp()
  5. self.partner_obj = self.env['res.partner']
  6. self.first_parent = self.partner_obj.create({
  7. 'name': 'MyFirstParentForTheAffiliate',
  8. 'type': 'contact',
  9. 'is_company': True,
  10. 'street': 'first parent street',
  11. 'street2': 'number 99',
  12. 'zip': 123,
  13. 'city': 'Test City',
  14. })
  15. self.second_parent = self.partner_obj.create({
  16. 'name': 'MySecondParentForTheAffiliate',
  17. 'type': 'contact',
  18. 'is_company': True,
  19. 'street': 'second parent street',
  20. 'street2': 'number 44',
  21. 'zip': 999,
  22. 'city': 'Test City',
  23. })
  24. # Check data integrity of the objects when an affiliate is given a new
  25. # parent. So both objects keeps their data.
  26. def test_change_parent_from_a_new_affiliate(self):
  27. new_affiliate = self.partner_obj.create({
  28. 'name': 'MyTestAffiliate',
  29. 'is_company': True,
  30. 'parent_id': self.first_parent.id,
  31. 'type': 'affiliate',
  32. 'street': 'affiliate street',
  33. 'street2': 'number 11',
  34. 'zip': 567,
  35. 'city': 'Test City',
  36. 'email': 'myAffiliate@test.com',
  37. })
  38. # Checks for data integrity in affiliate and his parent.
  39. self.assertTrue(new_affiliate, "The new affiliate have been created.")
  40. self.assertEquals(new_affiliate.type, 'affiliate',
  41. "Check type must be 'affiliate'")
  42. self.assertEquals(new_affiliate.parent_id.id, self.first_parent.id,
  43. "Must be child of the parent defined in the setup")
  44. self.assertEquals(new_affiliate.street, "affiliate street",
  45. "The street have been correctly set.")
  46. self.assertEquals(self.first_parent.street, "first parent street",
  47. "The parent continues with his original street")
  48. # Change the parent of the affiliate for the second one in the set-up.
  49. new_affiliate.parent_id = self.second_parent.id
  50. new_affiliate.onchange_parent_id()
  51. # The parent have been changed. And is not the first one.
  52. self.assertEquals(new_affiliate.parent_id.id, self.second_parent.id)
  53. # The affiliate keeps its data for the street. Not modified.
  54. self.assertEquals(new_affiliate.street, "affiliate street",
  55. "keeps the same street")
  56. # The data for the street of the first parent have not been changed.
  57. self.assertEquals(self.first_parent.street, "first parent street",
  58. "keeps the same street")
  59. # Check that the default value for 'type' defined by default in the view
  60. # is set correctly when a new affiliate is created.
  61. def test_new_affiliate_is_created_with_type_affiliate_by_default(self):
  62. new_affiliate = self.partner_obj.with_context(
  63. {'default_parent_id': self.first_parent.id,
  64. 'default_is_company': True,
  65. 'default_type': 'affiliate'
  66. }
  67. ).create({
  68. 'name': 'MyTestAffiliate',
  69. 'street': 'affiliate street',
  70. 'street2': 'number 11',
  71. 'zip': 567,
  72. 'city': 'Test City',
  73. 'email': 'myAffiliate@test.com',
  74. })
  75. self.assertEquals(new_affiliate.type, 'affiliate')