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
2.9 KiB

  1. # Copyright 2021 Tecnativa - Carlos Dauden
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
  3. from odoo.exceptions import UserError
  4. from odoo.tests import common
  5. class TestPartnerPricelistSearch(common.SavepointCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super().setUpClass()
  9. cls.pricelist_1 = cls.env["product.pricelist"].create(
  10. {"name": "Test pricelist 1"}
  11. )
  12. cls.pricelist_2 = cls.env["product.pricelist"].create(
  13. {"name": "Test pricelist 2"}
  14. )
  15. cls.customer_1 = cls.env["res.partner"].create(
  16. {"name": "Test customer 1", "property_product_pricelist": cls.pricelist_1}
  17. )
  18. cls.customer_2 = cls.env["res.partner"].create(
  19. {"name": "Test customer 2", "property_product_pricelist": cls.pricelist_2}
  20. )
  21. cls.partner_obj = cls.env["res.partner"]
  22. def test_partner_pricelist_search_equal(self):
  23. """Test search '='"""
  24. partners = self.partner_obj.search(
  25. [("property_product_pricelist", "=", self.pricelist_1.id)]
  26. )
  27. self.assertEqual(partners, self.customer_1)
  28. def test_partner_pricelist_search_in(self):
  29. """Test search 'in'"""
  30. partners = self.partner_obj.search(
  31. [
  32. (
  33. "property_product_pricelist",
  34. "in",
  35. (self.pricelist_1 | self.pricelist_2).ids,
  36. )
  37. ]
  38. )
  39. self.assertIn(self.customer_1, partners)
  40. self.assertIn(self.customer_2, partners)
  41. def test_partner_pricelist_search_not_equal(self):
  42. """Test search 'not equal'"""
  43. partners = self.partner_obj.search(
  44. [("property_product_pricelist", "!=", self.pricelist_1.id)]
  45. )
  46. self.assertNotIn(self.customer_1, partners)
  47. self.assertIn(self.customer_2, partners)
  48. def test_partner_pricelist_search_not_in(self):
  49. """Test search 'not in'"""
  50. partners = self.partner_obj.search(
  51. [
  52. (
  53. "property_product_pricelist",
  54. "not in",
  55. (self.pricelist_1 | self.pricelist_2).ids,
  56. )
  57. ]
  58. )
  59. self.assertNotIn(self.customer_1, partners)
  60. self.assertNotIn(self.customer_2, partners)
  61. def test_partner_pricelist_search_not_implemented(self):
  62. """Test search not implemented"""
  63. with self.assertRaises(UserError):
  64. self.partner_obj.search(
  65. [("property_product_pricelist", "ilike", "pricelist xx")]
  66. )
  67. def test_show_pricelist_partners(self):
  68. res = self.pricelist_1.show_pricelist_partners()
  69. self.assertEqual(self.partner_obj.search(res["domain"]), self.customer_1)
  70. res = (self.pricelist_1 | self.pricelist_2).show_pricelist_partners()
  71. self.assertEqual(
  72. self.partner_obj.search(res["domain"]), (self.customer_1 | self.customer_2)
  73. )