test_move_cancel_propagation.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests import tagged
  4. from .common import PurchaseTestCommon
  5. class TestMoveCancelPropagation(PurchaseTestCommon):
  6. @classmethod
  7. def setUpClass(cls):
  8. super().setUpClass()
  9. cls.customer = cls.env['res.partner'].create({'name': 'abc'})
  10. cls.group = cls.env['procurement.group'].create({'partner_id': cls.customer.id, 'name': 'New Group'})
  11. cls.warehouse = cls.env.ref('stock.warehouse0')
  12. cust_location = cls.env.ref('stock.stock_location_customers')
  13. seller = cls.env['product.supplierinfo'].create({
  14. 'partner_id': cls.customer.id,
  15. 'price': 100.0,
  16. })
  17. product = cls.env['product.product'].create({
  18. 'name': 'Geyser',
  19. 'type': 'product',
  20. 'route_ids': [(4, cls.route_mto), (4, cls.route_buy)],
  21. 'seller_ids': [(6, 0, [seller.id])],
  22. })
  23. cls.picking_out = cls.env['stock.picking'].create({
  24. 'location_id': cls.warehouse.out_type_id.default_location_src_id.id,
  25. 'location_dest_id': cust_location.id,
  26. 'partner_id': cls.customer.id,
  27. 'group_id': cls.group.id,
  28. 'picking_type_id': cls.env.ref('stock.picking_type_out').id,
  29. })
  30. cls.move = cls.env['stock.move'].create({
  31. 'name': product.name,
  32. 'product_id': product.id,
  33. 'product_uom_qty': 10,
  34. 'product_uom': product.uom_id.id,
  35. 'picking_id': cls.picking_out.id,
  36. 'group_id': cls.group.id,
  37. 'location_id': cls.warehouse.out_type_id.default_location_src_id.id,
  38. 'location_dest_id': cust_location.id,
  39. 'procure_method': 'make_to_order',
  40. })
  41. def test_01_cancel_draft_purchase_order_one_steps(self):
  42. """ Check the picking and moves status related PO, When canceling purchase order
  43. Ex.
  44. 1) Set one steps of receiption and delivery on the warehouse.
  45. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  46. 3) Cancel 'draft' purchase order should not cancel < Delivery >
  47. """
  48. self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'})
  49. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  50. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  51. self.picking_out.action_confirm()
  52. # Find PO related to picking.
  53. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  54. # Po should be create related picking.
  55. self.assertTrue(purchase_order, 'No purchase order created.')
  56. # Check status of Purchase Order
  57. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  58. # Cancel Purchase order.
  59. purchase_order.button_cancel()
  60. # Check the status of picking after canceling po.
  61. self.assertNotEqual(self.picking_out.state, 'cancel')
  62. def test_02_cancel_confirm_purchase_order_one_steps(self):
  63. """ Check the picking and moves status related purchase order, When canceling purchase order
  64. after confirming.
  65. Ex.
  66. 1) Set one steps of receiption and delivery on the warehouse.
  67. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  68. 3) Cancel 'confirmed' purchase order, should cancel releted < Receiption >
  69. but it should not cancel < Delivery > order.
  70. """
  71. self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'})
  72. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  73. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  74. self.picking_out.action_confirm()
  75. # Find PO related to picking.
  76. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  77. # Po should be create related picking.
  78. self.assertTrue(purchase_order, 'No purchase order created.')
  79. # Check status of Purchase Order
  80. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  81. purchase_order .button_confirm()
  82. picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
  83. # Cancel Purchase order.
  84. purchase_order .button_cancel()
  85. # Check the status of picking after canceling po.
  86. self.assertEqual(picking_in.state, 'cancel')
  87. self.assertNotEqual(self.picking_out.state, 'cancel')
  88. def test_03_cancel_draft_purchase_order_two_steps(self):
  89. """ Check the picking and moves status related PO, When canceling purchase order
  90. in 'draft' state.
  91. Ex.
  92. 1) Set two steps of receiption and delivery on the warehouse.
  93. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  94. 3) Cancel 'draft' purchase order should cancel < Input to Stock>
  95. but it should not cancel < PICK, Delivery >
  96. """
  97. self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'})
  98. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  99. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  100. self.picking_out.action_confirm()
  101. # Find purchase order related to picking.
  102. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  103. # Purchase order should be created for picking.
  104. self.assertTrue(purchase_order, 'No purchase order created.')
  105. picking_ids = self.env['stock.picking'].search([('group_id', '=', self.group.id)])
  106. internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id and r.group_id.id == self.group.id)
  107. pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id and r.group_id.id == self.group.id)
  108. # Check status of Purchase Order
  109. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  110. # Cancel Purchase order.
  111. purchase_order.button_cancel()
  112. # Check the status of picking after canceling po.
  113. for res in internal:
  114. self.assertEqual(res.state, 'cancel')
  115. self.assertNotEqual(pick.state, 'cancel')
  116. self.assertNotEqual(self.picking_out.state, 'cancel')
  117. def test_04_cancel_confirm_purchase_order_two_steps(self):
  118. """ Check the picking and moves status related PO, When canceling purchase order
  119. Ex.
  120. 1) Set 2 steps of receiption and delivery on the warehouse.
  121. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  122. 3) Cancel 'comfirm' purchase order should cancel releted < Receiption Picking IN, INT>
  123. not < PICK, SHIP >
  124. """
  125. self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'})
  126. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  127. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  128. self.picking_out.action_confirm()
  129. # Find PO related to picking.
  130. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  131. # Po should be create related picking.
  132. self.assertTrue(purchase_order, 'purchase order is created.')
  133. picking_ids = self.env['stock.picking'].search([('group_id', '=', self.group.id)])
  134. internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
  135. pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)
  136. # Check status of Purchase Order
  137. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  138. purchase_order.button_confirm()
  139. picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
  140. # Cancel Purchase order.
  141. purchase_order.button_cancel()
  142. # Check the status of picking after canceling po.
  143. self.assertEqual(picking_in.state, 'cancel')
  144. for res in internal:
  145. self.assertEqual(res.state, 'cancel')
  146. self.assertNotEqual(pick.state, 'cancel')
  147. self.assertNotEqual(self.picking_out.state, 'cancel')
  148. def test_05_cancel_draft_purchase_order_three_steps(self):
  149. """ Check the picking and moves status related PO, When canceling purchase order
  150. Ex.
  151. 1) Set 3 steps of receiption and delivery on the warehouse.
  152. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  153. 3) Cancel 'draft' purchase order should cancel releted < Receiption Picking IN>
  154. not < PICK, PACK, SHIP >
  155. """
  156. self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'})
  157. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  158. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  159. self.picking_out.action_confirm()
  160. # Find PO related to picking.
  161. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  162. # Po should be create related picking.
  163. self.assertTrue(purchase_order, 'No purchase order created.')
  164. picking_ids = self.env['stock.picking'].search([('group_id', '=', self.group.id)])
  165. internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
  166. pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)
  167. pack = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pack_type_id)
  168. # Check status of Purchase Order
  169. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  170. # Cancel Purchase order.
  171. purchase_order.button_cancel()
  172. # Check the status of picking after canceling po.
  173. for res in internal:
  174. self.assertEqual(res.state, 'cancel')
  175. self.assertNotEqual(pick.state, 'cancel')
  176. self.assertNotEqual(pack.state, 'cancel')
  177. self.assertNotEqual(self.picking_out.state, 'cancel')
  178. def test_06_cancel_confirm_purchase_order_three_steps(self):
  179. """ Check the picking and moves status related PO, When canceling purchase order
  180. Ex.
  181. 1) Set 3 steps of receiption and delivery on the warehouse.
  182. 2) Create Delivery order with mto move and confirm the order, related RFQ should be generated.
  183. 3) Cancel 'comfirm' purchase order should cancel releted < Receiption Picking IN, INT>
  184. not < PICK, PACK, SHIP >
  185. """
  186. self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'})
  187. self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  188. self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
  189. self.picking_out.action_confirm()
  190. # Find PO related to picking.
  191. purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
  192. # Po should be create related picking.
  193. self.assertTrue(purchase_order, 'No purchase order created.')
  194. picking_ids = self.env['stock.picking'].search([('group_id', '=', self.group.id)])
  195. internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
  196. pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)
  197. pack = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pack_type_id)
  198. # Check status of Purchase Order
  199. self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
  200. purchase_order.button_confirm()
  201. picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
  202. # Cancel Purchase order.
  203. purchase_order.button_cancel()
  204. # Check the status of picking after canceling po.
  205. self.assertEqual(picking_in.state, 'cancel')
  206. for res in internal:
  207. self.assertEqual(res.state, 'cancel')
  208. self.assertNotEqual(pick.state, 'cancel')
  209. self.assertNotEqual(pack.state, 'cancel')
  210. self.assertNotEqual(self.picking_out.state, 'cancel')
  211. def test_cancel_move_lines_operation(self):
  212. """Check for done and cancelled moves. Ensure that the RFQ cancellation
  213. will not impact the delivery state if it's already cancelled.
  214. """
  215. stock_location = self.env.ref('stock.stock_location_stock')
  216. customer_location = self.env.ref('stock.stock_location_customers')
  217. picking_type_out = self.env.ref('stock.picking_type_out')
  218. partner = self.env['res.partner'].create({
  219. 'name': 'Steve'
  220. })
  221. seller = self.env['product.supplierinfo'].create({
  222. 'partner_id': partner.id,
  223. 'price': 10.0,
  224. })
  225. product_car = self.env['product.product'].create({
  226. 'name': 'Car',
  227. 'type': 'product',
  228. 'route_ids': [(4, self.ref('stock.route_warehouse0_mto')), (4, self.ref('purchase_stock.route_warehouse0_buy'))],
  229. 'seller_ids': [(6, 0, [seller.id])],
  230. 'categ_id': self.env.ref('product.product_category_all').id,
  231. })
  232. customer_picking = self.env['stock.picking'].create({
  233. 'location_id': stock_location.id,
  234. 'location_dest_id': customer_location.id,
  235. 'partner_id': partner.id,
  236. 'picking_type_id': picking_type_out.id,
  237. })
  238. customer_move = self.env['stock.move'].create({
  239. 'name': 'move out',
  240. 'location_id': stock_location.id,
  241. 'location_dest_id': customer_location.id,
  242. 'product_id': product_car.id,
  243. 'product_uom': product_car.uom_id.id,
  244. 'product_uom_qty': 10.0,
  245. 'procure_method': 'make_to_order',
  246. 'picking_id': customer_picking.id,
  247. })
  248. customer_move._action_confirm()
  249. purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)])
  250. customer_move._action_cancel()
  251. self.assertEqual(customer_move.state, 'cancel', 'Move should be cancelled')
  252. purchase_order.button_cancel()
  253. self.assertEqual(customer_move.state, 'cancel', 'State of cancelled and done moves should not change.')