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.

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