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.

88 lines
3.2 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 .common import setup_test_model
  5. from .purchase_test import PurchaseTest, LineTest
  6. import logging
  7. _logger = logging.getLogger(__name__)
  8. @common.at_install(False)
  9. @common.post_install(True)
  10. class TestBaseException(common.SavepointCase):
  11. # pylint: disable=missing-return
  12. @classmethod
  13. def setUpClass(cls):
  14. super(TestBaseException, cls).setUpClass()
  15. setup_test_model(cls.env, [PurchaseTest, LineTest])
  16. cls.base_exception = cls.env['base.exception']
  17. cls.exception_rule = cls.env['exception.rule']
  18. cls.exception_confirm = cls.env['exception.rule.confirm']
  19. cls.exception_rule._fields['rule_group'].selection.append(
  20. ('test_base', 'test base exception')
  21. )
  22. cls.exception_rule._fields['model'].selection.append(
  23. ('base.exception.test.purchase',
  24. 'base.exception.test.purchase')
  25. )
  26. cls.exception_rule._fields['model'].selection.append(
  27. ('base.exception.test.purchase.line',
  28. 'base.exception.test.purchase.line')
  29. )
  30. cls.exceptionnozip = cls.env['exception.rule'].create({
  31. 'name': "No ZIP code on destination",
  32. 'sequence': 10,
  33. 'rule_group': "test_base",
  34. 'model': "base.exception.test.purchase",
  35. 'code': """if not test_base.partner_id.zip:
  36. failed=True""",
  37. })
  38. cls.exceptionno_minorder = cls.env['exception.rule'].create({
  39. 'name': "Min order except",
  40. 'sequence': 10,
  41. 'rule_group': "test_base",
  42. 'model': "base.exception.test.purchase",
  43. 'code': """if test_base.amount_total <= 200.0:
  44. failed=True""",
  45. })
  46. cls.exceptionno_lineqty = cls.env['exception.rule'].create({
  47. 'name': "Qty > 0",
  48. 'sequence': 10,
  49. 'rule_group': "test_base",
  50. 'model': "base.exception.test.purchase.line",
  51. 'code': """if test_base_line.qty <= 0:
  52. failed=True"""})
  53. def test_purchase_order_exception(self):
  54. partner = self.env.ref('base.res_partner_1')
  55. partner.zip = False
  56. potest1 = self.env['base.exception.test.purchase'].create({
  57. 'name': 'Test base exception to basic purchase',
  58. 'partner_id': partner.id,
  59. 'line_ids': [(0, 0, {'name': "line test",
  60. 'amount': 120.0,
  61. 'qty': 1.5})],
  62. })
  63. potest1.button_confirm()
  64. # Set ignore_exception flag (Done after ignore is selected at wizard)
  65. potest1.ignore_exception = True
  66. potest1.button_confirm()
  67. self.assertTrue(potest1.state == 'purchase')
  68. # Simulation the opening of the wizard exception_confirm and
  69. # set ignore_exception to True
  70. except_confirm = self.exception_confirm.with_context(
  71. {
  72. 'active_id': potest1.id,
  73. 'active_ids': [potest1.id],
  74. 'active_model': potest1._name
  75. }).new({'ignore': True})
  76. except_confirm.action_confirm()
  77. self.assertTrue(potest1.ignore_exception)