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.

74 lines
2.8 KiB

7 years ago
  1. # Copyright 2016 Akretion Mourad EL HADJ MIMOUNE
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. from odoo.exceptions import ValidationError
  5. from odoo import fields
  6. from .common import setup_test_model
  7. from .purchase_test import PurchaseTest, LineTest
  8. import logging
  9. _logger = logging.getLogger(__name__)
  10. @common.at_install(False)
  11. @common.post_install(True)
  12. class TestBaseException(common.SavepointCase):
  13. @classmethod
  14. def setUpClass(cls):
  15. super(TestBaseException, cls).setUpClass()
  16. setup_test_model(cls.env, [PurchaseTest, LineTest])
  17. cls.base_exception = cls.env['base.exception']
  18. cls.exception_rule = cls.env['exception.rule']
  19. if 'test_purchase_ids' not in cls.exception_rule._fields:
  20. field = fields.Many2many('base.exception.test.purchase')
  21. cls.exception_rule._add_field('test_purchase_ids', field)
  22. cls.exception_confirm = cls.env['exception.rule.confirm']
  23. cls.exception_rule._fields['model'].selection.append(
  24. ('base.exception.test.purchase', 'Purchase Order'))
  25. cls.exception_rule._fields['model'].selection.append(
  26. ('base.exception.test.purchase.line', 'Purchase Order Line'))
  27. cls.exceptionnozip = cls.env['exception.rule'].create({
  28. 'name': "No ZIP code on destination",
  29. 'sequence': 10,
  30. 'model': "base.exception.test.purchase",
  31. 'code': "if not obj.partner_id.zip: failed=True",
  32. })
  33. cls.exceptionno_minorder = cls.env['exception.rule'].create({
  34. 'name': "Min order except",
  35. 'sequence': 10,
  36. 'model': "base.exception.test.purchase",
  37. 'code': "if obj.amount_total <= 200.0: failed=True",
  38. })
  39. cls.exceptionno_lineqty = cls.env['exception.rule'].create({
  40. 'name': "Qty > 0",
  41. 'sequence': 10,
  42. 'model': "base.exception.test.purchase.line",
  43. 'code': "if obj.qty <= 0: failed=True"
  44. })
  45. def test_purchase_order_exception(self):
  46. partner = self.env.ref('base.res_partner_1')
  47. partner.zip = False
  48. potest1 = self.env['base.exception.test.purchase'].create({
  49. 'name': 'Test base exception to basic purchase',
  50. 'partner_id': partner.id,
  51. 'line_ids': [(0, 0, {
  52. 'name': "line test",
  53. 'amount': 120.0,
  54. 'qty': 1.5,
  55. })],
  56. })
  57. # Block because of exception during validation
  58. with self.assertRaises(ValidationError):
  59. potest1.button_confirm()
  60. # Test ignore exeception make possible for the po to validate
  61. potest1.ignore_exception = True
  62. potest1.button_confirm()
  63. self.assertTrue(potest1.state == 'purchase')