test_picking.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Lorenzo Battistini - Agile Business Group
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.exceptions import Warning as UserError
  6. from openerp.osv import osv
  7. class TestPickingBackToDraft(TransactionCase):
  8. def _create_picking(self):
  9. return self.env['stock.picking'].create({
  10. 'partner_id': self.partner.id,
  11. 'picking_type_id': self.env.ref('stock.picking_type_out').id,
  12. })
  13. def _create_move(self, picking, product, quantity=5.0):
  14. src_location = self.env.ref('stock.stock_location_stock')
  15. dest_location = self.env.ref('stock.stock_location_customers')
  16. return self.env['stock.move'].create({
  17. 'name': '/',
  18. 'picking_id': picking.id,
  19. 'product_id': product.id,
  20. 'product_uom_qty': quantity,
  21. 'product_uom': product.uom_id.id,
  22. 'location_id': src_location.id,
  23. 'location_dest_id': dest_location.id,
  24. })
  25. def setUp(self, *args, **kwargs):
  26. super(TestPickingBackToDraft, self).setUp(*args, **kwargs)
  27. self.partner = self.env.ref('base.res_partner_2')
  28. self.product1 = self.env.ref('product.product_product_33')
  29. self.product2 = self.env.ref('product.product_product_36')
  30. self.picking_a = self._create_picking()
  31. self.move_a_1 = self._create_move(
  32. self.picking_a, self.product1, quantity=1)
  33. self.move_a_2 = self._create_move(
  34. self.picking_a, self.product2, quantity=2)
  35. def test_back_to_draft(self):
  36. self.assertEqual(self.picking_a.state, 'draft')
  37. with self.assertRaises(UserError):
  38. self.picking_a.action_back_to_draft()
  39. self.picking_a.action_cancel()
  40. self.assertEqual(self.picking_a.state, 'cancel')
  41. self.picking_a.action_back_to_draft()
  42. self.assertEqual(self.picking_a.state, 'draft')
  43. self.picking_a.action_assign()
  44. self.assertEqual(self.picking_a.state, 'confirmed')
  45. with self.assertRaises(UserError):
  46. self.picking_a.action_back_to_draft()
  47. self.picking_a.action_cancel()
  48. self.assertEqual(self.picking_a.state, 'cancel')
  49. self.picking_a.action_back_to_draft()
  50. self.assertEqual(self.picking_a.state, 'draft')
  51. self.picking_a.action_confirm()
  52. self.assertEqual(self.picking_a.state, 'confirmed')
  53. self.picking_a.action_cancel()
  54. self.assertEqual(self.picking_a.state, 'cancel')
  55. self.picking_a.action_back_to_draft()
  56. self.assertEqual(self.picking_a.state, 'draft')
  57. self.picking_a.action_assign()
  58. self.assertEqual(self.picking_a.state, 'confirmed')
  59. self.picking_a.action_done()
  60. self.assertEqual(self.picking_a.state, 'done')
  61. with self.assertRaises(osv.except_osv):
  62. self.picking_a.action_cancel()
  63. with self.assertRaises(UserError):
  64. self.picking_a.action_back_to_draft()