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.

84 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Akretion Mourad EL HADJ MIMOUNE
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. # @common.at_install(False)
  8. # @common.post_install(True)
  9. class TestBaseException(common.TransactionCase):
  10. def setUp(self):
  11. super(TestBaseException, self).setUp()
  12. self.base_exception = self.env['base.exception']
  13. self.exception_rule = self.env['exception.rule']
  14. self.exception_confirm = self.env['exception.rule.confirm']
  15. self.exception_rule._fields['rule_group'].selection.append(
  16. ('test_base', 'test base exception')
  17. )
  18. self.exception_rule._fields['model'].selection.append(
  19. ('base.exception.test.purchase',
  20. 'base.exception.test.purchase')
  21. )
  22. self.exception_rule._fields['model'].selection.append(
  23. ('base.exception.test.purchase.line',
  24. 'base.exception.test.purchase.line')
  25. )
  26. self.exceptionnozip = self.env['exception.rule'].create({
  27. 'name': "No ZIP code on destination",
  28. 'sequence': 10,
  29. 'rule_group': "test_base",
  30. 'model': "base.exception.test.purchase",
  31. 'code': """if not test_base.partner_id.zip:
  32. failed=True""",
  33. })
  34. self.exceptionno_minorder = self.env['exception.rule'].create({
  35. 'name': "Min order except",
  36. 'sequence': 10,
  37. 'rule_group': "test_base",
  38. 'model': "base.exception.test.purchase",
  39. 'code': """if test_base.amount_total <= 200.0:
  40. failed=True""",
  41. })
  42. self.exceptionno_lineqty = self.env['exception.rule'].create({
  43. 'name': "Qty > 0",
  44. 'sequence': 10,
  45. 'rule_group': "test_base",
  46. 'model': "base.exception.test.purchase.line",
  47. 'code': """if test_base_line.qty <= 0:
  48. failed=True"""})
  49. def test_sale_order_exception(self):
  50. partner = self.env.ref('base.res_partner_1')
  51. partner.zip = False
  52. potest1 = self.env['base.exception.test.purchase'].create({
  53. 'name': 'Test base exception to basic purchase',
  54. 'partner_id': partner.id,
  55. 'line_ids': [(0, 0, {'name': "line test",
  56. 'amount': 120.0,
  57. 'qty': 1.5})],
  58. })
  59. potest1.button_confirm()
  60. # Set ignore_exception flag (Done after ignore is selected at wizard)
  61. potest1.ignore_exception = True
  62. potest1.button_confirm()
  63. self.assertTrue(potest1.state == 'purchase')
  64. # Simulation the opening of the wizard exception_confirm and
  65. # set ignore_exception to True
  66. except_confirm = self.exception_confirm.with_context(
  67. {
  68. 'active_id': potest1.id,
  69. 'active_ids': [potest1.id],
  70. 'active_model': potest1._name
  71. }).new({'ignore': True})
  72. except_confirm.action_confirm()
  73. self.assertTrue(potest1.ignore_exception)