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.

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