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.

99 lines
3.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 UAB Versada
  6. # (<http://www.versada.lt>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.tests import common
  23. from openerp.exceptions import ValidationError
  24. class TestCreditLimit(common.TransactionCase):
  25. def setUp(self):
  26. super(TestCreditLimit, self).setUp()
  27. self.partner_model = self.env['res.partner']
  28. self.partner = self.partner_model.create({
  29. 'name': 'Test Partner',
  30. 'is_company': False,
  31. 'credit_limit': 100,
  32. })
  33. self.partner_company = self.partner_model.create({
  34. 'name': 'Test Company',
  35. 'is_company': True,
  36. 'credit_limit': 100,
  37. })
  38. self.partner_company_contact = self.partner_model.create({
  39. 'name': 'Test Contact',
  40. 'is_company': False,
  41. 'parent_id': self.partner_company.id,
  42. })
  43. def test_credit_limit_not_reached(self):
  44. self.assertIsNone(
  45. self.partner.credit_limit_reached(
  46. credit_increase=99)
  47. )
  48. self.assertIsNone(
  49. self.partner_company.credit_limit_reached(
  50. credit_increase=99)
  51. )
  52. self.assertIsNone(
  53. self.partner_company_contact.credit_limit_reached(
  54. credit_increase=99)
  55. )
  56. def test_credit_limit_raises(self):
  57. with self.assertRaises(ValidationError):
  58. self.partner.credit_limit_reached(
  59. credit_increase=101)
  60. with self.assertRaises(ValidationError):
  61. self.partner_company.credit_limit_reached(
  62. credit_increase=101)
  63. with self.assertRaises(ValidationError):
  64. self.partner_company_contact.credit_limit_reached(
  65. credit_increase=101)
  66. def test_credit_limit_not_raises(self):
  67. self.assertTrue(
  68. self.partner.credit_limit_reached(
  69. credit_increase=101, raise_error=False)
  70. )
  71. self.assertTrue(
  72. self.partner_company.credit_limit_reached(
  73. credit_increase=101, raise_error=False)
  74. )
  75. self.assertTrue(
  76. self.partner_company_contact.credit_limit_reached(
  77. credit_increase=101, raise_error=False)
  78. )