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.

125 lines
4.7 KiB

  1. # Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests.common import SavepointCase
  4. class TestPartnerCompanyGroup(SavepointCase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super().setUpClass()
  8. cls.partner_model = cls.env["res.partner"]
  9. cls.company = cls.partner_model.create(
  10. {"name": "Test Company", "company_type": "company"}
  11. )
  12. cls.contact = cls.partner_model.create(
  13. {"name": "Test Contact", "type": "contact", "parent_id": cls.company.id}
  14. )
  15. currency = cls.env.ref("base.USD")
  16. cls.pricelist1 = cls.env["product.pricelist"].create(
  17. {"name": "Pricelist 01", "currency_id": currency.id}
  18. )
  19. cls.pricelist2 = cls.env["product.pricelist"].create(
  20. {"name": "Pricelist 02", "currency_id": currency.id}
  21. )
  22. cls.company_group1 = cls.env["res.partner"].create(
  23. {
  24. "name": "Company Group 01",
  25. "is_company": True,
  26. "property_product_pricelist": cls.pricelist1.id,
  27. }
  28. )
  29. cls.company_group2 = cls.env["res.partner"].create(
  30. {
  31. "name": "Company Group 02",
  32. "is_company": True,
  33. "property_product_pricelist": cls.pricelist2.id,
  34. }
  35. )
  36. cls.partner1 = cls.env["res.partner"].create(
  37. {
  38. "name": "Partner 01",
  39. "is_company": True,
  40. "property_product_pricelist": cls.pricelist1.id,
  41. "company_group_id": cls.company_group1.id,
  42. }
  43. )
  44. cls.partner2 = cls.env["res.partner"].create(
  45. {
  46. "name": "Partner 02",
  47. "is_company": True,
  48. "property_product_pricelist": cls.pricelist1.id,
  49. "company_group_id": cls.company_group1.id,
  50. }
  51. )
  52. def test_partner_company_group(self):
  53. self.company.write({"company_group_id": self.company.id})
  54. self.assertEqual(self.company.company_group_id, self.contact.company_group_id)
  55. def test_01_change_pricelist_partner(self):
  56. self.partner1.property_product_pricelist = self.pricelist2
  57. res = self.partner1._onchange_property_product_pricelist()
  58. self.assertEqual(
  59. {
  60. "warning": {
  61. "title": "Warning",
  62. "message": "The company group Company Group 01 has the pricelist "
  63. "Pricelist 01 (USD), that is different than the "
  64. "pricelist set on this contact",
  65. }
  66. },
  67. res,
  68. )
  69. self.partner1.property_product_pricelist = self.pricelist1
  70. res = self.partner1._onchange_property_product_pricelist()
  71. self.assertEqual({}, res)
  72. def test_02_change_company_group_partner(self):
  73. self.partner1.company_group_id = self.company_group2
  74. res = self.partner1._onchange_company_group_id()
  75. self.assertEqual(
  76. {
  77. "warning": {
  78. "title": "Warning",
  79. "message": "The company group Company Group 02 has the pricelist "
  80. "Pricelist 02 (USD), that is different than the "
  81. "pricelist set on this contact",
  82. }
  83. },
  84. res,
  85. )
  86. self.partner1.company_group_id = self.company_group1
  87. res = self.partner1._onchange_company_group_id()
  88. self.assertEqual({}, res)
  89. def test_03_change_pricelist_company_group(self):
  90. self.company_group1.property_product_pricelist = self.pricelist2
  91. res = self.company_group1._onchange_property_product_pricelist()
  92. self.assertEqual(
  93. {
  94. "warning": {
  95. "title": "Warning",
  96. "message": "This contact has members of a company group with "
  97. "different pricelists, the members are:\n"
  98. "\t- Partner 01\n\t- Partner 02\n",
  99. }
  100. },
  101. res,
  102. )
  103. self.partner1.property_product_pricelist = self.pricelist2
  104. res = self.company_group1._onchange_property_product_pricelist()
  105. self.assertEqual(
  106. {
  107. "warning": {
  108. "title": "Warning",
  109. "message": "This contact has members of a company group with "
  110. "different pricelists, the members are:\n"
  111. "\t- Partner 02\n",
  112. }
  113. },
  114. res,
  115. )
  116. self.partner2.property_product_pricelist = self.pricelist2
  117. res = self.company_group1._onchange_property_product_pricelist()
  118. self.assertEqual({}, res)