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.

100 lines
3.4 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.move_model = self.env['account.move']
  29. self.sales_journal_id = self.env['account.journal'].search(
  30. [('type', '=', 'sale')], limit=1)
  31. self.credit_account_id = self.env['account.account'].search(
  32. [('type', '=', 'other')], limit=1).id
  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. self.line_id_1 = [(0, 0, {
  44. 'name': 'Debit Line',
  45. 'partner_id': self.partner_company.id,
  46. 'account_id': self.partner_company.property_account_receivable.id,
  47. 'debit': 99}),
  48. (0, 0, {
  49. 'name': 'Debit Line',
  50. 'partner_id': self.partner_company.id,
  51. 'account_id': self.credit_account_id,
  52. 'credit': 99}),
  53. ]
  54. self.line_id_2 = [(0, 0, {
  55. 'name': 'Debit Line',
  56. 'partner_id': self.partner_company.id,
  57. 'account_id': self.partner_company.property_account_receivable.id,
  58. 'debit': 101}),
  59. (0, 0, {
  60. 'name': 'Debit Line',
  61. 'partner_id': self.partner_company.id,
  62. 'account_id': self.credit_account_id,
  63. 'credit': 101}),
  64. ]
  65. def test_credit_limit_validates(self):
  66. self.assertTrue(
  67. self.move_model.create({
  68. 'journal_id': self.sales_journal_id.id,
  69. 'line_id': self.line_id_1,
  70. 'state': 'draft'
  71. }).validate()
  72. )
  73. def test_credit_limit_not_validates(self):
  74. self.move_model.create({
  75. 'journal_id': self.sales_journal_id.id,
  76. 'line_id': self.line_id_1,
  77. 'state': 'draft'
  78. }).validate()
  79. with self.assertRaises(ValidationError):
  80. self.move_model.create({
  81. 'journal_id': self.sales_journal_id.id,
  82. 'line_id': self.line_id_2,
  83. 'state': 'draft'
  84. }).validate()