test_purchase_delete_order.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.exceptions import UserError
  4. from .common import PurchaseTestCommon
  5. class TestDeleteOrder(PurchaseTestCommon):
  6. def test_00_delete_order(self):
  7. ''' Testcase for deleting purchase order with purchase user group'''
  8. # In order to test delete process on purchase order,tried to delete a confirmed order and check Error Message.
  9. partner = self.env['res.partner'].create({'name': 'My Partner'})
  10. purchase_order = self.env['purchase.order'].create({
  11. 'partner_id': partner.id,
  12. 'state': 'purchase',
  13. })
  14. purchase_order_1 = purchase_order.with_user(self.res_users_purchase_user)
  15. with self.assertRaises(UserError):
  16. purchase_order_1.unlink()
  17. # Delete 'cancelled' purchase order with user group
  18. purchase_order = self.env['purchase.order'].create({
  19. 'partner_id': partner.id,
  20. 'state': 'purchase',
  21. })
  22. purchase_order_2 = purchase_order.with_user(self.res_users_purchase_user)
  23. purchase_order_2.button_cancel()
  24. self.assertEqual(purchase_order_2.state, 'cancel', 'PO is cancelled!')
  25. purchase_order_2.unlink()
  26. # Delete 'draft' purchase order with user group
  27. purchase_order = self.env['purchase.order'].create({
  28. 'partner_id': partner.id,
  29. 'state': 'draft',
  30. })
  31. purchase_order_3 = purchase_order.with_user(self.res_users_purchase_user)
  32. purchase_order_3.button_cancel()
  33. self.assertEqual(purchase_order_3.state, 'cancel', 'PO is cancelled!')
  34. purchase_order_3.unlink()