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.

85 lines
3.1 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. @classmethod
  12. def setUpClass(cls):
  13. super(TestBaseException, cls).setUpClass()
  14. setup_test_model(cls.env, [PurchaseTest, LineTest])
  15. cls.base_exception = cls.env['base.exception']
  16. cls.exception_rule = cls.env['exception.rule']
  17. cls.exception_confirm = cls.env['exception.rule.confirm']
  18. cls.exception_rule._fields['rule_group'].selection.append(
  19. ('test_base', 'Test Base Exception'))
  20. cls.exception_rule._fields['model'].selection.append(
  21. ('base.exception.test.purchase', 'Purchase Order'))
  22. cls.exception_rule._fields['model'].selection.append(
  23. ('base.exception.test.purchase.line', 'Purchase Order Line'))
  24. cls.exceptionnozip = cls.env['exception.rule'].create({
  25. 'name': "No ZIP code on destination",
  26. 'sequence': 10,
  27. 'rule_group': "test_base",
  28. 'model': "base.exception.test.purchase",
  29. 'code': "if not test_base.partner_id.zip: failed=True",
  30. })
  31. cls.exceptionno_minorder = cls.env['exception.rule'].create({
  32. 'name': "Min order except",
  33. 'sequence': 10,
  34. 'rule_group': "test_base",
  35. 'model': "base.exception.test.purchase",
  36. 'code': "if test_base.amount_total <= 200.0: failed=True",
  37. })
  38. cls.exceptionno_lineqty = cls.env['exception.rule'].create({
  39. 'name': "Qty > 0",
  40. 'sequence': 10,
  41. 'rule_group': "test_base",
  42. 'model': "base.exception.test.purchase.line",
  43. 'code': "if test_base_line.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. potest1.button_confirm()
  58. # Set ignore_exception flag (Done after ignore is selected at wizard)
  59. potest1.ignore_exception = True
  60. potest1.button_confirm()
  61. self.assertTrue(potest1.state == 'purchase')
  62. # Simulation the opening of the wizard exception_confirm and
  63. # set ignore_exception to True
  64. except_confirm = self.exception_confirm.with_context(
  65. {
  66. 'active_id': potest1.id,
  67. 'active_ids': [potest1.id],
  68. 'active_model': potest1._name
  69. }).new({'ignore': True})
  70. except_confirm.action_confirm()
  71. self.assertTrue(potest1.ignore_exception)