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. from odoo.exceptions import ValidationError
  5. from odoo import fields
  6. from .common import setup_test_model
  7. from .purchase_test import PurchaseTest, LineTest
  8. import logging
  9. _logger = logging.getLogger(__name__)
  10. @common.at_install(False)
  11. @common.post_install(True)
  12. class TestBaseException(common.SavepointCase):
  13. @classmethod
  14. def setUpClass(cls):
  15. super(TestBaseException, cls).setUpClass()
  16. setup_test_model(cls.env, [PurchaseTest, LineTest])
  17. cls.base_exception = cls.env["base.exception"]
  18. cls.exception_rule = cls.env["exception.rule"]
  19. if "test_purchase_ids" not in cls.exception_rule._fields:
  20. field = fields.Many2many("base.exception.test.purchase")
  21. cls.exception_rule._add_field("test_purchase_ids", field)
  22. cls.exception_confirm = cls.env["exception.rule.confirm"]
  23. cls.exception_rule._fields["model"].selection.append(
  24. ("base.exception.test.purchase", "Purchase Order")
  25. )
  26. cls.exception_rule._fields["model"].selection.append(
  27. ("base.exception.test.purchase.line", "Purchase Order Line")
  28. )
  29. cls.exceptionnozip = cls.env["exception.rule"].create(
  30. {
  31. "name": "No ZIP code on destination",
  32. "sequence": 10,
  33. "model": "base.exception.test.purchase",
  34. "code": "if not obj.partner_id.zip: failed=True",
  35. }
  36. )
  37. cls.exceptionno_minorder = cls.env["exception.rule"].create(
  38. {
  39. "name": "Min order except",
  40. "sequence": 10,
  41. "model": "base.exception.test.purchase",
  42. "code": "if obj.amount_total <= 200.0: failed=True",
  43. }
  44. )
  45. cls.exceptionno_lineqty = cls.env["exception.rule"].create(
  46. {
  47. "name": "Qty > 0",
  48. "sequence": 10,
  49. "model": "base.exception.test.purchase.line",
  50. "code": "if obj.qty <= 0: failed=True",
  51. }
  52. )
  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. {
  58. "name": "Test base exception to basic purchase",
  59. "partner_id": partner.id,
  60. "line_ids": [
  61. (0, 0, {"name": "line test", "amount": 120.0, "qty": 1.5})
  62. ],
  63. }
  64. )
  65. # Block because of exception during validation
  66. with self.assertRaises(ValidationError):
  67. potest1.button_confirm()
  68. # Test that we have linked exceptions
  69. self.assertTrue(potest1.exception_ids)
  70. # Test ignore exeception make possible for the po to validate
  71. potest1.ignore_exception = True
  72. potest1.button_confirm()
  73. self.assertTrue(potest1.state == "purchase")