test_packing.py 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests import Form
  4. from odoo.tests.common import TransactionCase
  5. from odoo.tools import float_round
  6. from odoo.exceptions import UserError
  7. class TestPackingCommon(TransactionCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestPackingCommon, cls).setUpClass()
  11. cls.stock_location = cls.env.ref('stock.stock_location_stock')
  12. cls.warehouse = cls.env['stock.warehouse'].search([('lot_stock_id', '=', cls.stock_location.id)], limit=1)
  13. cls.warehouse.write({'delivery_steps': 'pick_pack_ship'})
  14. cls.warehouse.int_type_id.reservation_method = 'manual'
  15. cls.pack_location = cls.warehouse.wh_pack_stock_loc_id
  16. cls.ship_location = cls.warehouse.wh_output_stock_loc_id
  17. cls.customer_location = cls.env.ref('stock.stock_location_customers')
  18. cls.productA = cls.env['product.product'].create({'name': 'Product A', 'type': 'product'})
  19. cls.productB = cls.env['product.product'].create({'name': 'Product B', 'type': 'product'})
  20. class TestPacking(TestPackingCommon):
  21. def test_put_in_pack(self):
  22. """ In a pick pack ship scenario, create two packs in pick and check that
  23. they are correctly recognised and handled by the pack and ship picking.
  24. Along this test, we'll use action_toggle_processed to process a pack
  25. from the entire_package_ids one2many and we'll directly fill the move
  26. lines, the latter is the behavior when the user did not enable the display
  27. of entire packs on the picking type.
  28. """
  29. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0)
  30. self.env['stock.quant']._update_available_quantity(self.productB, self.stock_location, 20.0)
  31. ship_move_a = self.env['stock.move'].create({
  32. 'name': 'The ship move',
  33. 'product_id': self.productA.id,
  34. 'product_uom_qty': 5.0,
  35. 'product_uom': self.productA.uom_id.id,
  36. 'location_id': self.ship_location.id,
  37. 'location_dest_id': self.customer_location.id,
  38. 'warehouse_id': self.warehouse.id,
  39. 'picking_type_id': self.warehouse.out_type_id.id,
  40. 'procure_method': 'make_to_order',
  41. 'state': 'draft',
  42. })
  43. ship_move_b = self.env['stock.move'].create({
  44. 'name': 'The ship move',
  45. 'product_id': self.productB.id,
  46. 'product_uom_qty': 5.0,
  47. 'product_uom': self.productB.uom_id.id,
  48. 'location_id': self.ship_location.id,
  49. 'location_dest_id': self.customer_location.id,
  50. 'warehouse_id': self.warehouse.id,
  51. 'picking_type_id': self.warehouse.out_type_id.id,
  52. 'procure_method': 'make_to_order',
  53. 'state': 'draft',
  54. })
  55. ship_move_a._assign_picking()
  56. ship_move_b._assign_picking()
  57. ship_move_a._action_confirm()
  58. ship_move_b._action_confirm()
  59. pack_move_a = ship_move_a.move_orig_ids[0]
  60. pick_move_a = pack_move_a.move_orig_ids[0]
  61. pick_picking = pick_move_a.picking_id
  62. packing_picking = pack_move_a.picking_id
  63. shipping_picking = ship_move_a.picking_id
  64. pick_picking.picking_type_id.show_entire_packs = True
  65. packing_picking.picking_type_id.show_entire_packs = True
  66. shipping_picking.picking_type_id.show_entire_packs = True
  67. pick_picking.action_assign()
  68. self.assertEqual(len(pick_picking.move_ids_without_package), 2)
  69. pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA).qty_done = 1.0
  70. pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB).qty_done = 2.0
  71. first_pack = pick_picking.action_put_in_pack()
  72. self.assertEqual(len(pick_picking.package_level_ids), 1, 'Put some products in pack should create a package_level')
  73. self.assertEqual(pick_picking.package_level_ids[0].state, 'new', 'A new pack should be in state "new"')
  74. pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA and ml.qty_done == 0.0).qty_done = 4.0
  75. pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB and ml.qty_done == 0.0).qty_done = 3.0
  76. second_pack = pick_picking.action_put_in_pack()
  77. self.assertEqual(len(pick_picking.move_ids_without_package), 0)
  78. self.assertEqual(len(packing_picking.move_ids_without_package), 2)
  79. pick_picking.button_validate()
  80. self.assertEqual(len(packing_picking.move_ids_without_package), 0)
  81. self.assertEqual(len(first_pack.quant_ids), 2)
  82. self.assertEqual(len(second_pack.quant_ids), 2)
  83. packing_picking.action_assign()
  84. self.assertEqual(len(packing_picking.package_level_ids), 2, 'Two package levels must be created after assigning picking')
  85. packing_picking.package_level_ids.write({'is_done': True})
  86. packing_picking._action_done()
  87. def test_pick_a_pack_confirm(self):
  88. pack = self.env['stock.quant.package'].create({'name': 'The pack to pick'})
  89. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0, package_id=pack)
  90. picking = self.env['stock.picking'].create({
  91. 'picking_type_id': self.warehouse.int_type_id.id,
  92. 'location_id': self.stock_location.id,
  93. 'location_dest_id': self.stock_location.id,
  94. 'state': 'draft',
  95. })
  96. picking.picking_type_id.show_entire_packs = True
  97. package_level = self.env['stock.package_level'].create({
  98. 'package_id': pack.id,
  99. 'picking_id': picking.id,
  100. 'company_id': picking.company_id.id,
  101. })
  102. self.assertEqual(package_level.state, 'draft',
  103. 'The package_level should be in draft as it has no moves, move lines and is not confirmed')
  104. picking.action_confirm()
  105. self.assertEqual(len(picking.move_ids_without_package), 0)
  106. self.assertEqual(len(picking.move_ids), 1,
  107. 'One move should be created when the package_level has been confirmed')
  108. self.assertEqual(len(package_level.move_ids), 1,
  109. 'The move should be in the package level')
  110. self.assertEqual(package_level.state, 'confirmed',
  111. 'The package level must be state confirmed when picking is confirmed')
  112. picking.action_assign()
  113. self.assertEqual(len(picking.move_ids), 1,
  114. 'You still have only one move when the picking is assigned')
  115. self.assertEqual(len(picking.move_ids.move_line_ids), 1,
  116. 'The move should have one move line which is the reservation')
  117. self.assertEqual(picking.move_line_ids.package_level_id.id, package_level.id,
  118. 'The move line created should be linked to the package level')
  119. self.assertEqual(picking.move_line_ids.package_id.id, pack.id,
  120. 'The move line must have been reserved on the package of the package_level')
  121. self.assertEqual(picking.move_line_ids.result_package_id.id, pack.id,
  122. 'The move line must have the same package as result package')
  123. self.assertEqual(package_level.state, 'assigned', 'The package level must be in state assigned')
  124. package_level.write({'is_done': True})
  125. self.assertEqual(len(package_level.move_line_ids), 1,
  126. 'The package level should still keep one move line after have been set to "done"')
  127. self.assertEqual(package_level.move_line_ids[0].qty_done, 20.0,
  128. 'All quantity in package must be procesed in move line')
  129. picking.button_validate()
  130. self.assertEqual(len(picking.move_ids), 1,
  131. 'You still have only one move when the picking is assigned')
  132. self.assertEqual(len(picking.move_ids.move_line_ids), 1,
  133. 'The move should have one move line which is the reservation')
  134. self.assertEqual(package_level.state, 'done', 'The package level must be in state done')
  135. self.assertEqual(pack.location_id.id, picking.location_dest_id.id,
  136. 'The quant package must be in the destination location')
  137. self.assertEqual(pack.quant_ids[0].location_id.id, picking.location_dest_id.id,
  138. 'The quant must be in the destination location')
  139. def test_pick_a_pack_cancel(self):
  140. """Cancel a reserved operation with a not-done package level (is_done=False)."""
  141. pack = self.env['stock.quant.package'].create({'name': 'The pack to pick'})
  142. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0, package_id=pack)
  143. picking = self.env['stock.picking'].create({
  144. 'picking_type_id': self.warehouse.int_type_id.id,
  145. 'location_id': self.stock_location.id,
  146. 'location_dest_id': self.stock_location.id,
  147. 'state': 'draft',
  148. })
  149. picking.picking_type_id.show_entire_packs = True
  150. package_level = self.env['stock.package_level'].create({
  151. 'package_id': pack.id,
  152. 'picking_id': picking.id,
  153. 'location_dest_id': self.stock_location.id,
  154. 'company_id': picking.company_id.id,
  155. })
  156. picking.action_confirm()
  157. picking.action_assign()
  158. self.assertEqual(package_level.state, 'assigned')
  159. self.assertTrue(package_level.move_line_ids)
  160. picking.action_cancel()
  161. self.assertEqual(package_level.state, 'cancel')
  162. self.assertFalse(package_level.move_line_ids)
  163. def test_pick_a_pack_cancel_is_done(self):
  164. """Cancel a reserved operation with a package level that is done (is_done=True)."""
  165. pack = self.env['stock.quant.package'].create({'name': 'The pack to pick'})
  166. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0, package_id=pack)
  167. picking = self.env['stock.picking'].create({
  168. 'picking_type_id': self.warehouse.int_type_id.id,
  169. 'location_id': self.stock_location.id,
  170. 'location_dest_id': self.stock_location.id,
  171. 'state': 'draft',
  172. })
  173. picking.picking_type_id.show_entire_packs = True
  174. package_level = self.env['stock.package_level'].create({
  175. 'package_id': pack.id,
  176. 'picking_id': picking.id,
  177. 'location_dest_id': self.stock_location.id,
  178. 'company_id': picking.company_id.id,
  179. })
  180. picking.action_confirm()
  181. picking.action_assign()
  182. self.assertEqual(package_level.state, 'assigned')
  183. self.assertTrue(package_level.move_line_ids)
  184. # By setting the package_level as 'done', all related lines will be kept
  185. # when cancelling the transfer
  186. package_level.is_done = True
  187. picking.action_cancel()
  188. self.assertEqual(picking.state, 'cancel')
  189. self.assertEqual(package_level.state, 'cancel')
  190. self.assertTrue(package_level.move_line_ids)
  191. self.assertTrue(
  192. all(package_level.move_line_ids.mapped(lambda l: l.state == 'cancel'))
  193. )
  194. def test_multi_pack_reservation(self):
  195. """ When we move entire packages, it is possible to have a multiple times
  196. the same package in package level list, we make sure that only one is reserved,
  197. and that the location_id of the package is the one where the package is once it
  198. is reserved.
  199. """
  200. pack = self.env['stock.quant.package'].create({'name': 'The pack to pick'})
  201. shelf1_location = self.env['stock.location'].create({
  202. 'name': 'shelf1',
  203. 'usage': 'internal',
  204. 'location_id': self.stock_location.id,
  205. })
  206. self.env['stock.quant']._update_available_quantity(self.productA, shelf1_location, 20.0, package_id=pack)
  207. picking = self.env['stock.picking'].create({
  208. 'picking_type_id': self.warehouse.int_type_id.id,
  209. 'location_id': self.stock_location.id,
  210. 'location_dest_id': self.stock_location.id,
  211. 'state': 'draft',
  212. })
  213. package_level = self.env['stock.package_level'].create({
  214. 'package_id': pack.id,
  215. 'picking_id': picking.id,
  216. 'company_id': picking.company_id.id,
  217. })
  218. package_level = self.env['stock.package_level'].create({
  219. 'package_id': pack.id,
  220. 'picking_id': picking.id,
  221. 'company_id': picking.company_id.id,
  222. })
  223. picking.action_confirm()
  224. self.assertEqual(picking.package_level_ids.mapped('location_id.id'), [shelf1_location.id],
  225. 'The package levels should still in the same location after confirmation.')
  226. picking.action_assign()
  227. package_level_reserved = picking.package_level_ids.filtered(lambda pl: pl.state == 'assigned')
  228. package_level_confirmed = picking.package_level_ids.filtered(lambda pl: pl.state == 'confirmed')
  229. self.assertEqual(package_level_reserved.location_id.id, shelf1_location.id, 'The reserved package level must be reserved in shelf1')
  230. self.assertEqual(package_level_confirmed.location_id.id, shelf1_location.id, 'The not reserved package should keep its location')
  231. picking.do_unreserve()
  232. self.assertEqual(picking.package_level_ids.mapped('location_id.id'), [shelf1_location.id],
  233. 'The package levels should have back the original location.')
  234. picking.package_level_ids.write({'is_done': True})
  235. picking.action_assign()
  236. package_level_reserved = picking.package_level_ids.filtered(lambda pl: pl.state == 'assigned')
  237. package_level_confirmed = picking.package_level_ids.filtered(lambda pl: pl.state == 'confirmed')
  238. self.assertEqual(package_level_reserved.location_id.id, shelf1_location.id, 'The reserved package level must be reserved in shelf1')
  239. self.assertEqual(package_level_confirmed.location_id.id, shelf1_location.id, 'The not reserved package should keep its location')
  240. self.assertEqual(picking.package_level_ids.mapped('is_done'), [True, True], 'Both package should still done')
  241. def test_put_in_pack_to_different_location(self):
  242. """ Hitting 'Put in pack' button while some move lines go to different
  243. location should trigger a wizard. This wizard applies the same destination
  244. location to all the move lines
  245. """
  246. self.warehouse.in_type_id.show_reserved = True
  247. shelf1_location = self.env['stock.location'].create({
  248. 'name': 'shelf1',
  249. 'usage': 'internal',
  250. 'location_id': self.stock_location.id,
  251. })
  252. shelf2_location = self.env['stock.location'].create({
  253. 'name': 'shelf2',
  254. 'usage': 'internal',
  255. 'location_id': self.stock_location.id,
  256. })
  257. picking = self.env['stock.picking'].create({
  258. 'picking_type_id': self.warehouse.in_type_id.id,
  259. 'location_id': self.customer_location.id,
  260. 'location_dest_id': self.stock_location.id,
  261. 'state': 'draft',
  262. })
  263. ship_move_a = self.env['stock.move'].create({
  264. 'name': 'move 1',
  265. 'product_id': self.productA.id,
  266. 'product_uom_qty': 5.0,
  267. 'product_uom': self.productA.uom_id.id,
  268. 'location_id': self.customer_location.id,
  269. 'location_dest_id': shelf1_location.id,
  270. 'picking_id': picking.id,
  271. 'state': 'draft',
  272. })
  273. picking.action_confirm()
  274. picking.action_assign()
  275. picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA).qty_done = 5.0
  276. picking.action_put_in_pack()
  277. pack1 = self.env['stock.quant.package'].search([])[-1]
  278. picking.write({
  279. 'move_line_ids': [(0, 0, {
  280. 'product_id': self.productB.id,
  281. 'reserved_uom_qty': 7.0,
  282. 'qty_done': 7.0,
  283. 'product_uom_id': self.productB.uom_id.id,
  284. 'location_id': self.customer_location.id,
  285. 'location_dest_id': shelf2_location.id,
  286. 'picking_id': picking.id,
  287. 'state': 'confirmed',
  288. })]
  289. })
  290. picking.write({
  291. 'move_line_ids': [(0, 0, {
  292. 'product_id': self.productA.id,
  293. 'reserved_uom_qty': 5.0,
  294. 'qty_done': 5.0,
  295. 'product_uom_id': self.productA.uom_id.id,
  296. 'location_id': self.customer_location.id,
  297. 'location_dest_id': shelf1_location.id,
  298. 'picking_id': picking.id,
  299. 'state': 'confirmed',
  300. })]
  301. })
  302. wizard_values = picking.action_put_in_pack()
  303. wizard = self.env[(wizard_values.get('res_model'))].browse(wizard_values.get('res_id'))
  304. wizard.location_dest_id = shelf2_location.id
  305. wizard.action_done()
  306. picking._action_done()
  307. pack2 = self.env['stock.quant.package'].search([])[-1]
  308. self.assertEqual(pack2.location_id.id, shelf2_location.id, 'The package must be stored in shelf2')
  309. self.assertEqual(pack1.location_id.id, shelf1_location.id, 'The package must be stored in shelf1')
  310. qp1 = pack2.quant_ids[0]
  311. qp2 = pack2.quant_ids[1]
  312. self.assertEqual(qp1.quantity + qp2.quantity, 12, 'The quant has not the good quantity')
  313. def test_move_picking_with_package(self):
  314. """
  315. 355.4 rounded with 0.01 precision is 355.40000000000003.
  316. check that nonetheless, moving a picking is accepted
  317. """
  318. self.assertEqual(self.productA.uom_id.rounding, 0.01)
  319. self.assertEqual(
  320. float_round(355.4, precision_rounding=self.productA.uom_id.rounding),
  321. 355.40000000000003,
  322. )
  323. location_dict = {
  324. 'location_id': self.stock_location.id,
  325. }
  326. quant = self.env['stock.quant'].create({
  327. **location_dict,
  328. **{'product_id': self.productA.id, 'quantity': 355.4}, # important number
  329. })
  330. package = self.env['stock.quant.package'].create({
  331. **location_dict, **{'quant_ids': [(6, 0, [quant.id])]},
  332. })
  333. location_dict.update({
  334. 'state': 'draft',
  335. 'location_dest_id': self.ship_location.id,
  336. })
  337. move = self.env['stock.move'].create({
  338. **location_dict,
  339. **{
  340. 'name': "XXX",
  341. 'product_id': self.productA.id,
  342. 'product_uom': self.productA.uom_id.id,
  343. 'product_uom_qty': 355.40000000000003, # other number
  344. }})
  345. picking = self.env['stock.picking'].create({
  346. **location_dict,
  347. **{
  348. 'picking_type_id': self.warehouse.in_type_id.id,
  349. 'move_ids': [(6, 0, [move.id])],
  350. }})
  351. picking.action_confirm()
  352. picking.action_assign()
  353. move.quantity_done = move.reserved_availability
  354. picking._action_done()
  355. # if we managed to get there, there was not any exception
  356. # complaining that 355.4 is not 355.40000000000003. Good job!
  357. def test_move_picking_with_package_2(self):
  358. """ Generate two move lines going to different location in the same
  359. package.
  360. """
  361. shelf1 = self.env['stock.location'].create({
  362. 'location_id': self.stock_location.id,
  363. 'name': 'Shelf 1',
  364. })
  365. shelf2 = self.env['stock.location'].create({
  366. 'location_id': self.stock_location.id,
  367. 'name': 'Shelf 2',
  368. })
  369. package = self.env['stock.quant.package'].create({})
  370. picking = self.env['stock.picking'].create({
  371. 'picking_type_id': self.warehouse.in_type_id.id,
  372. 'location_id': self.stock_location.id,
  373. 'location_dest_id': self.stock_location.id,
  374. 'state': 'draft',
  375. })
  376. self.env['stock.move.line'].create({
  377. 'location_id': self.stock_location.id,
  378. 'location_dest_id': shelf1.id,
  379. 'product_id': self.productA.id,
  380. 'product_uom_id': self.productA.uom_id.id,
  381. 'qty_done': 5.0,
  382. 'picking_id': picking.id,
  383. 'result_package_id': package.id,
  384. })
  385. self.env['stock.move.line'].create({
  386. 'location_id': self.stock_location.id,
  387. 'location_dest_id': shelf2.id,
  388. 'product_id': self.productA.id,
  389. 'product_uom_id': self.productA.uom_id.id,
  390. 'qty_done': 5.0,
  391. 'picking_id': picking.id,
  392. 'result_package_id': package.id,
  393. })
  394. picking.action_confirm()
  395. with self.assertRaises(UserError):
  396. picking._action_done()
  397. def test_pack_in_receipt_two_step_single_putway(self):
  398. """ Checks all works right in the following specific corner case:
  399. * For a two-step receipt, receives two products using the same putaway
  400. * Puts these products in a package then valid the receipt.
  401. * Cancels the automatically generated internal transfer then create a new one.
  402. * In this internal transfer, adds the package then valid it.
  403. """
  404. grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
  405. grp_multi_step_rule = self.env.ref('stock.group_adv_location')
  406. grp_pack = self.env.ref('stock.group_tracking_lot')
  407. self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]})
  408. self.env.user.write({'groups_id': [(3, grp_multi_step_rule.id)]})
  409. self.env.user.write({'groups_id': [(3, grp_pack.id)]})
  410. self.warehouse.reception_steps = 'two_steps'
  411. # Settings of receipt.
  412. self.warehouse.in_type_id.show_operations = True
  413. self.warehouse.in_type_id.show_entire_packs = True
  414. self.warehouse.in_type_id.show_reserved = True
  415. # Settings of internal transfer.
  416. self.warehouse.int_type_id.show_operations = True
  417. self.warehouse.int_type_id.show_entire_packs = True
  418. self.warehouse.int_type_id.show_reserved = True
  419. # Creates two new locations for putaway.
  420. location_form = Form(self.env['stock.location'])
  421. location_form.name = 'Shelf A'
  422. location_form.location_id = self.stock_location
  423. loc_shelf_A = location_form.save()
  424. # Creates a new putaway rule for productA and productB.
  425. putaway_A = self.env['stock.putaway.rule'].create({
  426. 'product_id': self.productA.id,
  427. 'location_in_id': self.stock_location.id,
  428. 'location_out_id': loc_shelf_A.id,
  429. })
  430. putaway_B = self.env['stock.putaway.rule'].create({
  431. 'product_id': self.productB.id,
  432. 'location_in_id': self.stock_location.id,
  433. 'location_out_id': loc_shelf_A.id,
  434. })
  435. self.stock_location.putaway_rule_ids = [(4, putaway_A.id, 0), (4, putaway_B.id, 0)]
  436. # Create a new receipt with the two products.
  437. receipt_form = Form(self.env['stock.picking'])
  438. receipt_form.picking_type_id = self.warehouse.in_type_id
  439. # Add 2 lines
  440. with receipt_form.move_ids_without_package.new() as move_line:
  441. move_line.product_id = self.productA
  442. move_line.product_uom_qty = 1
  443. with receipt_form.move_ids_without_package.new() as move_line:
  444. move_line.product_id = self.productB
  445. move_line.product_uom_qty = 1
  446. receipt = receipt_form.save()
  447. receipt.action_confirm()
  448. # Adds quantities then packs them and valids the receipt.
  449. receipt_form = Form(receipt)
  450. with receipt_form.move_line_ids_without_package.edit(0) as move_line:
  451. move_line.qty_done = 1
  452. with receipt_form.move_line_ids_without_package.edit(1) as move_line:
  453. move_line.qty_done = 1
  454. receipt = receipt_form.save()
  455. receipt.action_put_in_pack()
  456. receipt.button_validate()
  457. receipt_package = receipt.package_level_ids_details[0]
  458. self.assertEqual(receipt_package.location_dest_id.id, receipt.location_dest_id.id)
  459. self.assertEqual(
  460. receipt_package.move_line_ids[0].location_dest_id.id,
  461. receipt.location_dest_id.id)
  462. self.assertEqual(
  463. receipt_package.move_line_ids[1].location_dest_id.id,
  464. receipt.location_dest_id.id)
  465. # Checks an internal transfer was created following the validation of the receipt.
  466. internal_transfer = self.env['stock.picking'].search([
  467. ('picking_type_id', '=', self.warehouse.int_type_id.id)
  468. ], order='id desc', limit=1)
  469. self.assertEqual(internal_transfer.origin, receipt.name)
  470. self.assertEqual(
  471. len(internal_transfer.package_level_ids_details), 1)
  472. internal_package = internal_transfer.package_level_ids_details[0]
  473. self.assertNotEqual(
  474. internal_package.location_dest_id.id,
  475. internal_transfer.location_dest_id.id)
  476. self.assertEqual(
  477. internal_package.location_dest_id.id,
  478. putaway_A.location_out_id.id,
  479. "The package destination location must be the one from the putaway.")
  480. self.assertEqual(
  481. internal_package.move_line_ids[0].location_dest_id.id,
  482. putaway_A.location_out_id.id,
  483. "The move line destination location must be the one from the putaway.")
  484. self.assertEqual(
  485. internal_package.move_line_ids[1].location_dest_id.id,
  486. putaway_A.location_out_id.id,
  487. "The move line destination location must be the one from the putaway.")
  488. # Cancels the internal transfer and creates a new one.
  489. internal_transfer.action_cancel()
  490. # @api.depends('picking_type_id.show_operations')
  491. # def _compute_show_operations(self):
  492. # ...
  493. # if self.env.context.get('force_detailed_view'):
  494. # picking.show_operations = True
  495. internal_form = Form(self.env['stock.picking'].with_context(force_detailed_view=True))
  496. internal_form.picking_type_id = self.warehouse.int_type_id
  497. # The test specifically removes the ability to see the location fields
  498. # grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
  499. # self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]})
  500. # Hence, `internal_form.location_id` shouldn't be changed
  501. with internal_form.package_level_ids_details.new() as pack_line:
  502. pack_line.package_id = receipt_package.package_id
  503. internal_transfer = internal_form.save()
  504. # Checks the package fields have been correctly set.
  505. internal_package = internal_transfer.package_level_ids_details[0]
  506. self.assertEqual(
  507. internal_package.location_dest_id.id,
  508. internal_transfer.location_dest_id.id)
  509. internal_transfer.action_assign()
  510. self.assertNotEqual(
  511. internal_package.location_dest_id.id,
  512. internal_transfer.location_dest_id.id)
  513. self.assertEqual(
  514. internal_package.location_dest_id.id,
  515. putaway_A.location_out_id.id,
  516. "The package destination location must be the one from the putaway.")
  517. self.assertEqual(
  518. internal_package.move_line_ids[0].location_dest_id.id,
  519. putaway_A.location_out_id.id,
  520. "The move line destination location must be the one from the putaway.")
  521. self.assertEqual(
  522. internal_package.move_line_ids[1].location_dest_id.id,
  523. putaway_A.location_out_id.id,
  524. "The move line destination location must be the one from the putaway.")
  525. internal_transfer.button_validate()
  526. def test_pack_in_receipt_two_step_multi_putaway(self):
  527. """ Checks all works right in the following specific corner case:
  528. * For a two-step receipt, receives two products using two putaways
  529. targeting different locations.
  530. * Puts these products in a package then valid the receipt.
  531. * Cancels the automatically generated internal transfer then create a new one.
  532. * In this internal transfer, adds the package then valid it.
  533. """
  534. grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
  535. grp_multi_step_rule = self.env.ref('stock.group_adv_location')
  536. grp_pack = self.env.ref('stock.group_tracking_lot')
  537. self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]})
  538. self.env.user.write({'groups_id': [(3, grp_multi_step_rule.id)]})
  539. self.env.user.write({'groups_id': [(3, grp_pack.id)]})
  540. self.warehouse.reception_steps = 'two_steps'
  541. # Settings of receipt.
  542. self.warehouse.in_type_id.show_operations = True
  543. self.warehouse.in_type_id.show_entire_packs = True
  544. self.warehouse.in_type_id.show_reserved = True
  545. # Settings of internal transfer.
  546. self.warehouse.int_type_id.show_operations = True
  547. self.warehouse.int_type_id.show_entire_packs = True
  548. self.warehouse.int_type_id.show_reserved = True
  549. # Creates two new locations for putaway.
  550. location_form = Form(self.env['stock.location'])
  551. location_form.name = 'Shelf A'
  552. location_form.location_id = self.stock_location
  553. loc_shelf_A = location_form.save()
  554. location_form = Form(self.env['stock.location'])
  555. location_form.name = 'Shelf B'
  556. location_form.location_id = self.stock_location
  557. loc_shelf_B = location_form.save()
  558. # Creates a new putaway rule for productA and productB.
  559. putaway_A = self.env['stock.putaway.rule'].create({
  560. 'product_id': self.productA.id,
  561. 'location_in_id': self.stock_location.id,
  562. 'location_out_id': loc_shelf_A.id,
  563. })
  564. putaway_B = self.env['stock.putaway.rule'].create({
  565. 'product_id': self.productB.id,
  566. 'location_in_id': self.stock_location.id,
  567. 'location_out_id': loc_shelf_B.id,
  568. })
  569. self.stock_location.putaway_rule_ids = [(4, putaway_A.id, 0), (4, putaway_B.id, 0)]
  570. # location_form = Form(self.stock_location)
  571. # location_form.putaway_rule_ids = [(4, putaway_A.id, 0), (4, putaway_B.id, 0), ],
  572. # self.stock_location = location_form.save()
  573. # Create a new receipt with the two products.
  574. receipt_form = Form(self.env['stock.picking'])
  575. receipt_form.picking_type_id = self.warehouse.in_type_id
  576. # Add 2 lines
  577. with receipt_form.move_ids_without_package.new() as move_line:
  578. move_line.product_id = self.productA
  579. move_line.product_uom_qty = 1
  580. with receipt_form.move_ids_without_package.new() as move_line:
  581. move_line.product_id = self.productB
  582. move_line.product_uom_qty = 1
  583. receipt = receipt_form.save()
  584. receipt.action_confirm()
  585. # Adds quantities then packs them and valids the receipt.
  586. receipt_form = Form(receipt)
  587. with receipt_form.move_line_ids_without_package.edit(0) as move_line:
  588. move_line.qty_done = 1
  589. with receipt_form.move_line_ids_without_package.edit(1) as move_line:
  590. move_line.qty_done = 1
  591. receipt = receipt_form.save()
  592. receipt.action_put_in_pack()
  593. receipt.button_validate()
  594. receipt_package = receipt.package_level_ids_details[0]
  595. self.assertEqual(receipt_package.location_dest_id.id, receipt.location_dest_id.id)
  596. self.assertEqual(
  597. receipt_package.move_line_ids[0].location_dest_id.id,
  598. receipt.location_dest_id.id)
  599. self.assertEqual(
  600. receipt_package.move_line_ids[1].location_dest_id.id,
  601. receipt.location_dest_id.id)
  602. # Checks an internal transfer was created following the validation of the receipt.
  603. internal_transfer = self.env['stock.picking'].search([
  604. ('picking_type_id', '=', self.warehouse.int_type_id.id)
  605. ], order='id desc', limit=1)
  606. self.assertEqual(internal_transfer.origin, receipt.name)
  607. self.assertEqual(
  608. len(internal_transfer.package_level_ids_details), 1)
  609. internal_package = internal_transfer.package_level_ids_details[0]
  610. self.assertEqual(
  611. internal_package.location_dest_id.id,
  612. internal_transfer.location_dest_id.id)
  613. self.assertNotEqual(
  614. internal_package.location_dest_id.id,
  615. putaway_A.location_out_id.id,
  616. "The package destination location must be the one from the picking.")
  617. self.assertNotEqual(
  618. internal_package.move_line_ids[0].location_dest_id.id,
  619. putaway_A.location_out_id.id,
  620. "The move line destination location must be the one from the picking.")
  621. self.assertNotEqual(
  622. internal_package.move_line_ids[1].location_dest_id.id,
  623. putaway_A.location_out_id.id,
  624. "The move line destination location must be the one from the picking.")
  625. # Cancels the internal transfer and creates a new one.
  626. internal_transfer.action_cancel()
  627. # @api.depends('picking_type_id.show_operations')
  628. # def _compute_show_operations(self):
  629. # ...
  630. # if self.env.context.get('force_detailed_view'):
  631. # picking.show_operations = True
  632. internal_form = Form(self.env['stock.picking'].with_context(force_detailed_view=True))
  633. internal_form.picking_type_id = self.warehouse.int_type_id
  634. # The test specifically removes the ability to see the location fields
  635. # grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
  636. # self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]})
  637. # Hence, `internal_form.location_id` shouldn't be changed
  638. with internal_form.package_level_ids_details.new() as pack_line:
  639. pack_line.package_id = receipt_package.package_id
  640. internal_transfer = internal_form.save()
  641. # Checks the package fields have been correctly set.
  642. internal_package = internal_transfer.package_level_ids_details[0]
  643. self.assertEqual(
  644. internal_package.location_dest_id.id,
  645. internal_transfer.location_dest_id.id)
  646. internal_transfer.action_assign()
  647. self.assertEqual(
  648. internal_package.location_dest_id.id,
  649. internal_transfer.location_dest_id.id)
  650. self.assertNotEqual(
  651. internal_package.location_dest_id.id,
  652. putaway_A.location_out_id.id,
  653. "The package destination location must be the one from the picking.")
  654. self.assertNotEqual(
  655. internal_package.move_line_ids[0].location_dest_id.id,
  656. putaway_A.location_out_id.id,
  657. "The move line destination location must be the one from the picking.")
  658. self.assertNotEqual(
  659. internal_package.move_line_ids[1].location_dest_id.id,
  660. putaway_A.location_out_id.id,
  661. "The move line destination location must be the one from the picking.")
  662. internal_transfer.button_validate()
  663. def test_partial_put_in_pack(self):
  664. """ Create a simple move in a delivery. Reserve the quantity but set as quantity done only a part.
  665. Call Put In Pack button. """
  666. self.productA.tracking = 'lot'
  667. lot1 = self.env['stock.lot'].create({
  668. 'product_id': self.productA.id,
  669. 'name': '00001',
  670. 'company_id': self.warehouse.company_id.id
  671. })
  672. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0, lot_id=lot1)
  673. ship_move_a = self.env['stock.move'].create({
  674. 'name': 'The ship move',
  675. 'product_id': self.productA.id,
  676. 'product_uom_qty': 5.0,
  677. 'product_uom': self.productA.uom_id.id,
  678. 'location_id': self.ship_location.id,
  679. 'location_dest_id': self.customer_location.id,
  680. 'warehouse_id': self.warehouse.id,
  681. 'picking_type_id': self.warehouse.out_type_id.id,
  682. 'procure_method': 'make_to_order',
  683. 'state': 'draft',
  684. })
  685. ship_move_a._assign_picking()
  686. ship_move_a._action_confirm()
  687. pack_move_a = ship_move_a.move_orig_ids[0]
  688. pick_move_a = pack_move_a.move_orig_ids[0]
  689. pick_picking = pick_move_a.picking_id
  690. pick_picking.picking_type_id.show_entire_packs = True
  691. pick_picking.action_assign()
  692. pick_picking.move_line_ids.qty_done = 3
  693. first_pack = pick_picking.action_put_in_pack()
  694. def test_action_assign_package_level(self):
  695. """calling _action_assign on move does not erase lines' "result_package_id"
  696. At the end of the method ``StockMove._action_assign()``, the method
  697. ``StockPicking._check_entire_pack()`` is called. This method compares
  698. the move lines with the quants of their source package, and if the entire
  699. package is moved at once in the same transfer, a ``stock.package_level`` is
  700. created. On creation of a ``stock.package_level``, the result package of
  701. the move lines is directly updated with the entire package.
  702. This is good on the first assign of the move, but when we call assign for
  703. the second time on a move, for instance because it was made partially available
  704. and we want to assign the remaining, it can override the result package we
  705. selected before.
  706. An override of ``StockPicking._check_move_lines_map_quant_package()`` ensures
  707. that we ignore:
  708. * picked lines (qty_done > 0)
  709. * lines with a different result package already
  710. """
  711. package = self.env["stock.quant.package"].create({"name": "Src Pack"})
  712. dest_package1 = self.env["stock.quant.package"].create({"name": "Dest Pack1"})
  713. # Create new picking: 120 productA
  714. picking_form = Form(self.env['stock.picking'])
  715. picking_form.picking_type_id = self.warehouse.pick_type_id
  716. with picking_form.move_ids_without_package.new() as move_line:
  717. move_line.product_id = self.productA
  718. move_line.product_uom_qty = 120
  719. picking = picking_form.save()
  720. # mark as TO-DO
  721. picking.action_confirm()
  722. # Update quantity on hand: 100 units in package
  723. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 100, package_id=package)
  724. # Check Availability
  725. picking.action_assign()
  726. self.assertEqual(picking.state, "assigned")
  727. self.assertEqual(picking.package_level_ids.package_id, package)
  728. move = picking.move_ids
  729. line = move.move_line_ids
  730. # change the result package and set a qty_done
  731. line.qty_done = 100
  732. line.result_package_id = dest_package1
  733. # Update quantity on hand: 20 units in new_package
  734. new_package = self.env["stock.quant.package"].create({"name": "New Pack"})
  735. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20, package_id=new_package)
  736. # Check Availability
  737. picking.action_assign()
  738. # Check that result package is not changed on first line
  739. new_line = move.move_line_ids - line
  740. self.assertRecordValues(
  741. line + new_line,
  742. [
  743. {"qty_done": 100, "result_package_id": dest_package1.id},
  744. {"qty_done": 0, "result_package_id": new_package.id},
  745. ],
  746. )
  747. def test_entire_pack_overship(self):
  748. """
  749. Test the scenario of overshipping: we send the customer an entire package, even though it might be more than
  750. what they initially ordered, and update the quantity on the sales order to reflect what was actually sent.
  751. """
  752. self.warehouse.delivery_steps = 'ship_only'
  753. package = self.env["stock.quant.package"].create({"name": "Src Pack"})
  754. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 100, package_id=package)
  755. # Required for `package_level_ids_details` to be visible in the view
  756. # <page string="Detailed Operations" attrs="{'invisible': [('show_operations', '=', False)]}">
  757. # <field name="package_level_ids_details"
  758. # attrs="{'invisible': ['|', ('picking_type_entire_packs', '=', False), ('show_operations', '=', False)]}"
  759. self.warehouse.out_type_id.show_operations = True
  760. self.warehouse.out_type_id.show_entire_packs = True
  761. picking = self.env['stock.picking'].create({
  762. 'location_id': self.stock_location.id,
  763. 'location_dest_id': self.customer_location.id,
  764. 'picking_type_id': self.warehouse.out_type_id.id,
  765. })
  766. with Form(picking) as picking_form:
  767. with picking_form.move_ids_without_package.new() as move:
  768. move.product_id = self.productA
  769. move.product_uom_qty = 75
  770. picking.action_confirm()
  771. picking.action_assign()
  772. with Form(picking) as picking_form:
  773. with picking_form.package_level_ids_details.new() as package_level:
  774. package_level.package_id = package
  775. self.assertEqual(len(picking.move_ids), 1, 'Should have only 1 stock move')
  776. self.assertEqual(len(picking.move_ids), 1, 'Should have only 1 stock move')
  777. with Form(picking) as picking_form:
  778. with picking_form.package_level_ids_details.edit(0) as package_level:
  779. package_level.is_done = True
  780. action = picking.button_validate()
  781. self.assertEqual(action, True, 'Should not open wizard')
  782. for ml in picking.move_line_ids:
  783. self.assertEqual(ml.package_id, package, 'move_line.package')
  784. self.assertEqual(ml.result_package_id, package, 'move_line.result_package')
  785. self.assertEqual(ml.state, 'done', 'move_line.state')
  786. quant = package.quant_ids.filtered(lambda q: q.location_id == self.customer_location)
  787. self.assertEqual(len(quant), 1, 'Should have quant at customer location')
  788. self.assertEqual(quant.reserved_quantity, 0, 'quant.reserved_quantity should = 0')
  789. self.assertEqual(quant.quantity, 100.0, 'quant.quantity should = 100')
  790. self.assertEqual(sum(ml.qty_done for ml in picking.move_line_ids), 100.0, 'total move_line.qty_done should = 100')
  791. backorders = self.env['stock.picking'].search([('backorder_id', '=', picking.id)])
  792. self.assertEqual(len(backorders), 0, 'Should not create a backorder')
  793. def test_remove_package(self):
  794. """
  795. In the overshipping scenario, if I remove the package after adding it, we should not remove the associated
  796. stock move.
  797. """
  798. self.warehouse.delivery_steps = 'ship_only'
  799. package = self.env["stock.quant.package"].create({"name": "Src Pack"})
  800. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 100, package_id=package)
  801. self.warehouse.out_type_id.show_entire_packs = True
  802. picking = self.env['stock.picking'].create({
  803. 'location_id': self.stock_location.id,
  804. 'location_dest_id': self.customer_location.id,
  805. 'picking_type_id': self.warehouse.out_type_id.id,
  806. })
  807. with Form(picking) as picking_form:
  808. with picking_form.move_ids_without_package.new() as move:
  809. move.product_id = self.productA
  810. move.product_uom_qty = 75
  811. picking.action_assign()
  812. # @api.depends('picking_type_id.show_operations')
  813. # def _compute_show_operations(self):
  814. # ...
  815. # if self.env.context.get('force_detailed_view'):
  816. # picking.show_operations = True
  817. with Form(picking.with_context(force_detailed_view=True)) as picking_form:
  818. with picking_form.package_level_ids_details.new() as package_level:
  819. package_level.package_id = package
  820. with Form(picking) as picking_form:
  821. picking_form.package_level_ids.remove(0)
  822. self.assertEqual(len(picking.move_ids), 1, 'Should have only 1 stock move')
  823. def test_picking_state_with_null_qty(self):
  824. receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=False))
  825. picking_type_id = self.warehouse.out_type_id
  826. receipt_form.picking_type_id = picking_type_id
  827. with receipt_form.move_ids_without_package.new() as move_line:
  828. move_line.product_id = self.productA
  829. move_line.product_uom_qty = 10
  830. with receipt_form.move_ids_without_package.new() as move_line:
  831. move_line.product_id = self.productB
  832. move_line.product_uom_qty = 10
  833. receipt = receipt_form.save()
  834. receipt.action_confirm()
  835. self.assertEqual(receipt.state, 'confirmed')
  836. receipt.move_ids_without_package[1].product_uom_qty = 0
  837. self.assertEqual(receipt.state, 'confirmed')
  838. receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=True))
  839. picking_type_id = self.warehouse.out_type_id
  840. receipt_form.picking_type_id = picking_type_id
  841. with receipt_form.move_ids_without_package.new() as move_line:
  842. move_line.product_id = self.productA
  843. move_line.quantity_done = 10
  844. with receipt_form.move_ids_without_package.new() as move_line:
  845. move_line.product_id = self.productB
  846. move_line.quantity_done = 10
  847. receipt = receipt_form.save()
  848. receipt.action_confirm()
  849. self.assertEqual(receipt.state, 'assigned')
  850. receipt.move_ids_without_package[1].product_uom_qty = 0
  851. self.assertEqual(receipt.state, 'assigned')
  852. def test_2_steps_and_backorder(self):
  853. """ When creating a backorder with a package, the latter should be reserved in the new picking. Moreover,
  854. the initial picking shouldn't have any line about this package """
  855. def create_picking(pick_type, from_loc, to_loc):
  856. picking = self.env['stock.picking'].create({
  857. 'picking_type_id': pick_type.id,
  858. 'location_id': from_loc.id,
  859. 'location_dest_id': to_loc.id,
  860. })
  861. move_A, move_B = self.env['stock.move'].create([{
  862. 'name': self.productA.name,
  863. 'product_id': self.productA.id,
  864. 'product_uom_qty': 1,
  865. 'product_uom': self.productA.uom_id.id,
  866. 'picking_id': picking.id,
  867. 'location_id': from_loc.id,
  868. 'location_dest_id': to_loc.id,
  869. }, {
  870. 'name': self.productB.name,
  871. 'product_id': self.productB.id,
  872. 'product_uom_qty': 1,
  873. 'product_uom': self.productB.uom_id.id,
  874. 'picking_id': picking.id,
  875. 'location_id': from_loc.id,
  876. 'location_dest_id': to_loc.id,
  877. }])
  878. picking.action_confirm()
  879. picking.action_assign()
  880. return picking, move_A, move_B
  881. self.warehouse.delivery_steps = 'pick_ship'
  882. pick_type = self.warehouse.pick_type_id
  883. delivery_type = self.warehouse.out_type_id
  884. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 1)
  885. self.env['stock.quant']._update_available_quantity(self.productB, self.stock_location, 1)
  886. picking, moveA, moveB = create_picking(pick_type, pick_type.default_location_src_id, pick_type.default_location_dest_id)
  887. moveA.move_line_ids.qty_done = 1
  888. picking.action_put_in_pack()
  889. moveB.move_line_ids.qty_done = 1
  890. picking.action_put_in_pack()
  891. picking.button_validate()
  892. # Required for `package_level_ids_details` to be visible in the view
  893. # <page string="Detailed Operations" attrs="{'invisible': [('show_operations', '=', False)]}">
  894. # <field name="package_level_ids_details"
  895. # attrs="{'invisible': ['|', ('picking_type_entire_packs', '=', False), ('show_operations', '=', False)]}"
  896. delivery_type.show_operations = True
  897. delivery_type.show_entire_packs = True
  898. picking, _, _ = create_picking(delivery_type, delivery_type.default_location_src_id, self.customer_location)
  899. packB = picking.package_level_ids[1]
  900. with Form(picking) as picking_form:
  901. with picking_form.package_level_ids_details.edit(0) as package_level:
  902. package_level.is_done = True
  903. action_data = picking.button_validate()
  904. backorder_wizard = Form(self.env['stock.backorder.confirmation'].with_context(action_data['context'])).save()
  905. backorder_wizard.process()
  906. bo = self.env['stock.picking'].search([('backorder_id', '=', picking.id)])
  907. self.assertNotIn(packB, picking.package_level_ids)
  908. self.assertEqual(packB, bo.package_level_ids)
  909. self.assertEqual(bo.package_level_ids.state, 'assigned')
  910. def test_package_and_sub_location(self):
  911. """
  912. Suppose there are some products P available in shelf1, a child location of the pack location.
  913. When moving these P to another child location of pack location, the source location of the
  914. related package level should be shelf1
  915. """
  916. shelf1_location = self.env['stock.location'].create({
  917. 'name': 'shelf1',
  918. 'usage': 'internal',
  919. 'location_id': self.pack_location.id,
  920. })
  921. shelf2_location = self.env['stock.location'].create({
  922. 'name': 'shelf2',
  923. 'usage': 'internal',
  924. 'location_id': self.pack_location.id,
  925. })
  926. pack = self.env['stock.quant.package'].create({'name': 'Super Package'})
  927. self.env['stock.quant']._update_available_quantity(self.productA, shelf1_location, 20.0, package_id=pack)
  928. picking = self.env['stock.picking'].create({
  929. 'picking_type_id': self.warehouse.in_type_id.id,
  930. 'location_id': self.pack_location.id,
  931. 'location_dest_id': shelf2_location.id,
  932. })
  933. package_level = self.env['stock.package_level'].create({
  934. 'package_id': pack.id,
  935. 'picking_id': picking.id,
  936. 'company_id': picking.company_id.id,
  937. })
  938. self.assertEqual(package_level.location_id, shelf1_location)
  939. picking.action_confirm()
  940. package_level.is_done = True
  941. picking.button_validate()
  942. self.assertEqual(package_level.location_id, shelf1_location)
  943. def test_pack_in_receipt_two_step_multi_putaway_02(self):
  944. """
  945. Suppose a product P, its weight is equal to 1kg
  946. We have 100 x P on two pallets.
  947. Receipt in two steps + Sub locations in WH/Stock + Storage Category
  948. The Storage Category adds some constraints on weight/pallets capacity
  949. """
  950. warehouse = self.stock_location.warehouse_id
  951. warehouse.reception_steps = "two_steps"
  952. self.productA.weight = 1.0
  953. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_stock_storage_categories').id)]})
  954. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_stock_multi_locations').id)]})
  955. # Required for `result_package_id` to be visible in the view
  956. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_tracking_lot').id)]})
  957. package_type = self.env['stock.package.type'].create({
  958. 'name': "Super Pallet",
  959. })
  960. package_01, package_02 = self.env['stock.quant.package'].create([{
  961. 'name': 'Pallet %s' % i,
  962. 'package_type_id': package_type.id,
  963. } for i in [1, 2]])
  964. # max 100kg (so 100 x P) and max 1 pallet -> we will work with pallets,
  965. # so the pallet capacity constraint should be the effective one
  966. stor_category = self.env['stock.storage.category'].create({
  967. 'name': 'Super Storage Category',
  968. 'max_weight': 100,
  969. 'package_capacity_ids': [(0, 0, {
  970. 'package_type_id': package_type.id,
  971. 'quantity': 1,
  972. })]
  973. })
  974. # 3 sub locations with the storage category
  975. # (the third location should never be used)
  976. sub_loc_01, sub_loc_02, dummy = self.env['stock.location'].create([{
  977. 'name': 'Sub Location %s' % i,
  978. 'usage': 'internal',
  979. 'location_id': self.stock_location.id,
  980. 'storage_category_id': stor_category.id,
  981. } for i in [1, 2, 3]])
  982. self.env['stock.putaway.rule'].create({
  983. 'location_in_id': self.stock_location.id,
  984. 'location_out_id': self.stock_location.id,
  985. 'package_type_ids': [(4, package_type.id)],
  986. 'storage_category_id': stor_category.id,
  987. })
  988. # Receive 100 x P
  989. receipt_picking = self.env['stock.picking'].create({
  990. 'picking_type_id': warehouse.in_type_id.id,
  991. 'location_id': self.env.ref('stock.stock_location_suppliers').id,
  992. 'location_dest_id': warehouse.wh_input_stock_loc_id.id,
  993. })
  994. self.env['stock.move'].create({
  995. 'name': self.productA.name,
  996. 'product_id': self.productA.id,
  997. 'product_uom': self.productA.uom_id.id,
  998. 'product_uom_qty': 100.0,
  999. 'picking_id': receipt_picking.id,
  1000. 'location_id': receipt_picking.location_id.id,
  1001. 'location_dest_id': receipt_picking.location_dest_id.id,
  1002. })
  1003. receipt_picking.action_confirm()
  1004. # Distribute the products on two pallets, one with 49 x P and a second
  1005. # one with 51 x P (to easy the debugging in case of trouble)
  1006. move_form = Form(receipt_picking.move_ids, view="stock.view_stock_move_operations")
  1007. with move_form.move_line_ids.edit(0) as line:
  1008. line.qty_done = 49
  1009. line.result_package_id = package_01
  1010. with move_form.move_line_ids.new() as line:
  1011. line.qty_done = 51
  1012. line.result_package_id = package_02
  1013. move_form.save()
  1014. receipt_picking.button_validate()
  1015. # We are in two-steps receipt -> check the internal picking
  1016. internal_picking = self.env['stock.picking'].search([], order='id desc', limit=1)
  1017. self.assertRecordValues(internal_picking.move_line_ids, [
  1018. {'reserved_uom_qty': 51, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_01.id},
  1019. {'reserved_uom_qty': 49, 'qty_done': 0, 'result_package_id': package_01.id, 'location_dest_id': sub_loc_02.id},
  1020. ])
  1021. # Change the constraints of the storage category:
  1022. # max 75kg (so 75 x P) and max 2 pallet -> this time, the weight
  1023. # constraint should be the effective one
  1024. stor_category.max_weight = 75
  1025. stor_category.package_capacity_ids.quantity = 2
  1026. internal_picking.do_unreserve()
  1027. internal_picking.action_assign()
  1028. self.assertRecordValues(internal_picking.move_line_ids, [
  1029. {'reserved_uom_qty': 51, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_01.id},
  1030. {'reserved_uom_qty': 49, 'qty_done': 0, 'result_package_id': package_01.id, 'location_dest_id': sub_loc_02.id},
  1031. ])
  1032. move_form = Form(internal_picking.move_ids, view="stock.view_stock_move_operations")
  1033. # lines order is reversed: [Pallet 02, Pallet 01]
  1034. with move_form.move_line_ids.edit(0) as line:
  1035. line.qty_done = 51
  1036. with move_form.move_line_ids.edit(1) as line:
  1037. line.qty_done = 49
  1038. move_form.save()
  1039. self.assertRecordValues(internal_picking.move_line_ids, [
  1040. {'reserved_uom_qty': 51, 'qty_done': 51, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_01.id},
  1041. {'reserved_uom_qty': 49, 'qty_done': 49, 'result_package_id': package_01.id, 'location_dest_id': sub_loc_02.id},
  1042. ])
  1043. def test_pack_in_receipt_two_step_multi_putaway_03(self):
  1044. """
  1045. Two sublocations (max 100kg, max 2 pallet)
  1046. Two products P1, P2, weight = 1kg
  1047. There are 10 x P1 on a pallet in the first sub location
  1048. Receive a pallet of 50 x P1 + 50 x P2 => because of weight constraint, should be redirected to the
  1049. second sub location
  1050. Then, same with max 200kg max 1 pallet => same result, this time because of pallet count constraint
  1051. """
  1052. warehouse = self.stock_location.warehouse_id
  1053. warehouse.reception_steps = "two_steps"
  1054. self.productA.weight = 1.0
  1055. self.productB.weight = 1.0
  1056. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_stock_storage_categories').id)]})
  1057. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_stock_multi_locations').id)]})
  1058. # Required for `result_package_id` to be visible in the view
  1059. self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_tracking_lot').id)]})
  1060. package_type = self.env['stock.package.type'].create({
  1061. 'name': "Super Pallet",
  1062. })
  1063. package_01, package_02 = self.env['stock.quant.package'].create([{
  1064. 'name': 'Pallet %s' % i,
  1065. 'package_type_id': package_type.id,
  1066. } for i in [1, 2]])
  1067. # max 100kg and max 2 pallets
  1068. stor_category = self.env['stock.storage.category'].create({
  1069. 'name': 'Super Storage Category',
  1070. 'max_weight': 100,
  1071. 'package_capacity_ids': [(0, 0, {
  1072. 'package_type_id': package_type.id,
  1073. 'quantity': 2,
  1074. })]
  1075. })
  1076. # 3 sub locations with the storage category
  1077. # (the third location should never be used)
  1078. sub_loc_01, sub_loc_02, dummy = self.env['stock.location'].create([{
  1079. 'name': 'Sub Location %s' % i,
  1080. 'usage': 'internal',
  1081. 'location_id': self.stock_location.id,
  1082. 'storage_category_id': stor_category.id,
  1083. } for i in [1, 2, 3]])
  1084. self.env['stock.quant']._update_available_quantity(self.productA, sub_loc_01, 10, package_id=package_01)
  1085. self.env['stock.putaway.rule'].create({
  1086. 'location_in_id': self.stock_location.id,
  1087. 'location_out_id': self.stock_location.id,
  1088. 'package_type_ids': [(4, package_type.id)],
  1089. 'storage_category_id': stor_category.id,
  1090. })
  1091. # Receive 50 x P_A and 50 x P_B
  1092. receipt_picking = self.env['stock.picking'].create({
  1093. 'picking_type_id': warehouse.in_type_id.id,
  1094. 'location_id': self.env.ref('stock.stock_location_suppliers').id,
  1095. 'location_dest_id': warehouse.wh_input_stock_loc_id.id,
  1096. })
  1097. self.env['stock.move'].create([{
  1098. 'name': p.name,
  1099. 'product_id': p.id,
  1100. 'product_uom': p.uom_id.id,
  1101. 'product_uom_qty': 50,
  1102. 'picking_id': receipt_picking.id,
  1103. 'location_id': receipt_picking.location_id.id,
  1104. 'location_dest_id': receipt_picking.location_dest_id.id,
  1105. } for p in [self.productA, self.productB]])
  1106. receipt_picking.action_confirm()
  1107. move_form = Form(receipt_picking.move_ids[0], view="stock.view_stock_move_operations")
  1108. with move_form.move_line_ids.edit(0) as line:
  1109. line.qty_done = 50
  1110. line.result_package_id = package_02
  1111. move_form.save()
  1112. move_form = Form(receipt_picking.move_ids[1], view="stock.view_stock_move_operations")
  1113. with move_form.move_line_ids.edit(0) as line:
  1114. line.qty_done = 50
  1115. line.result_package_id = package_02
  1116. move_form.save()
  1117. receipt_picking.button_validate()
  1118. # We are in two-steps receipt -> check the internal picking
  1119. internal_picking = self.env['stock.picking'].search([], order='id desc', limit=1)
  1120. self.assertRecordValues(internal_picking.move_line_ids, [
  1121. {'product_id': self.productA.id, 'reserved_uom_qty': 50, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_02.id},
  1122. {'product_id': self.productB.id, 'reserved_uom_qty': 50, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_02.id},
  1123. ])
  1124. # Change the constraints of the storage category:
  1125. # max 200kg and max 1 pallet
  1126. stor_category.max_weight = 200
  1127. stor_category.package_capacity_ids.quantity = 1
  1128. internal_picking.do_unreserve()
  1129. internal_picking.action_assign()
  1130. self.assertRecordValues(internal_picking.move_line_ids, [
  1131. {'product_id': self.productA.id, 'reserved_uom_qty': 50, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_02.id},
  1132. {'product_id': self.productB.id, 'reserved_uom_qty': 50, 'qty_done': 0, 'result_package_id': package_02.id, 'location_dest_id': sub_loc_02.id},
  1133. ])
  1134. def test_pack_in_receipt_two_step_multi_putaway_04(self):
  1135. """
  1136. Create a putaway rules for package type T and storage category SC. SC
  1137. only allows same products and has a maximum of 2 x T. Four SC locations
  1138. L1, L2, L3 and L4.
  1139. First, move a package that contains two different products: should not
  1140. redirect to L1/L2 because of the "same products" contraint.
  1141. Then, add one T-package (with product P01) at L1 and move 2 T-packages
  1142. (both with product P01): one should be redirected to L1 and the second
  1143. one to L2
  1144. Finally, move 3 T-packages (two with 1xP01, one with 1xP02): one P01
  1145. should be redirected to L2 and the second one to L3 (because of capacity
  1146. constraint), then P02 should be redirected to L4 (because of "same
  1147. product" policy)
  1148. """
  1149. self.warehouse.reception_steps = "two_steps"
  1150. supplier_location = self.env.ref('stock.stock_location_suppliers')
  1151. input_location = self.warehouse.wh_input_stock_loc_id
  1152. package_type = self.env['stock.package.type'].create({
  1153. 'name': "package type",
  1154. })
  1155. storage_category = self.env['stock.storage.category'].create({
  1156. 'name': "storage category",
  1157. 'allow_new_product': "same",
  1158. 'max_weight': 1000,
  1159. 'package_capacity_ids': [(0, 0, {
  1160. 'package_type_id': package_type.id,
  1161. 'quantity': 2,
  1162. })],
  1163. })
  1164. loc01, loc02, loc03, loc04 = self.env['stock.location'].create([{
  1165. 'name': 'loc 0%d' % i,
  1166. 'usage': 'internal',
  1167. 'location_id': self.stock_location.id,
  1168. 'storage_category_id': storage_category.id,
  1169. } for i in range(1, 5)])
  1170. self.env['stock.putaway.rule'].create({
  1171. 'location_in_id': self.stock_location.id,
  1172. 'location_out_id': self.stock_location.id,
  1173. 'storage_category_id': storage_category.id,
  1174. 'package_type_ids': [(4, package_type.id, 0)],
  1175. })
  1176. receipt = self.env['stock.picking'].create({
  1177. 'picking_type_id': self.warehouse.in_type_id.id,
  1178. 'location_id': supplier_location.id,
  1179. 'location_dest_id': input_location.id,
  1180. 'move_ids': [(0, 0, {
  1181. 'name': p.name,
  1182. 'location_id': supplier_location.id,
  1183. 'location_dest_id': input_location.id,
  1184. 'product_id': p.id,
  1185. 'product_uom': p.uom_id.id,
  1186. 'product_uom_qty': 1.0,
  1187. }) for p in (self.productA, self.productB)],
  1188. })
  1189. receipt.action_confirm()
  1190. moves = receipt.move_ids
  1191. moves.move_line_ids.qty_done = 1
  1192. moves.move_line_ids.result_package_id = self.env['stock.quant.package'].create({'package_type_id': package_type.id})
  1193. receipt.button_validate()
  1194. internal_picking = moves.move_dest_ids.picking_id
  1195. self.assertEqual(internal_picking.move_line_ids.location_dest_id, self.stock_location,
  1196. 'Storage location only accepts one same product. Here the package contains two different '
  1197. 'products so it should not be redirected.')
  1198. internal_picking.action_cancel()
  1199. # Second test part
  1200. package = self.env['stock.quant.package'].create({'package_type_id': package_type.id})
  1201. self.env['stock.quant']._update_available_quantity(self.productA, loc01, 1.0, package_id=package)
  1202. receipt = self.env['stock.picking'].create({
  1203. 'picking_type_id': self.warehouse.in_type_id.id,
  1204. 'location_id': supplier_location.id,
  1205. 'location_dest_id': input_location.id,
  1206. 'move_ids': [(0, 0, {
  1207. 'name': self.productA.name,
  1208. 'location_id': supplier_location.id,
  1209. 'location_dest_id': input_location.id,
  1210. 'product_id': self.productA.id,
  1211. 'product_uom': self.productA.uom_id.id,
  1212. 'product_uom_qty': 2.0,
  1213. })],
  1214. })
  1215. receipt.action_confirm()
  1216. receipt.do_unreserve()
  1217. self.env['stock.move.line'].create([{
  1218. 'move_id': receipt.move_ids.id,
  1219. 'qty_done': 1,
  1220. 'product_id': self.productA.id,
  1221. 'product_uom_id': self.productA.uom_id.id,
  1222. 'location_id': supplier_location.id,
  1223. 'location_dest_id': input_location.id,
  1224. 'result_package_id': self.env['stock.quant.package'].create({'package_type_id': package_type.id}).id,
  1225. 'picking_id': receipt.id,
  1226. } for _ in range(2)])
  1227. receipt.button_validate()
  1228. internal_transfer = receipt.move_ids.move_dest_ids.picking_id
  1229. self.assertEqual(internal_transfer.move_line_ids.location_dest_id, loc01 | loc02,
  1230. 'There is already one package at L1, so the first SML should be redirected to L1 '
  1231. 'and the second one to L2')
  1232. internal_transfer.move_line_ids.qty_done = 1
  1233. internal_transfer.button_validate()
  1234. # Third part (move 3 packages, 2 x P01 and 1 x P02)
  1235. receipt = self.env['stock.picking'].create({
  1236. 'picking_type_id': self.warehouse.in_type_id.id,
  1237. 'location_id': supplier_location.id,
  1238. 'location_dest_id': input_location.id,
  1239. 'move_ids': [(0, 0, {
  1240. 'name': product.name,
  1241. 'location_id': supplier_location.id,
  1242. 'location_dest_id': input_location.id,
  1243. 'product_id': product.id,
  1244. 'product_uom': product.uom_id.id,
  1245. 'product_uom_qty': qty,
  1246. }) for qty, product in [(2.0, self.productA), (1.0, self.productB)]],
  1247. })
  1248. receipt.action_confirm()
  1249. receipt.do_unreserve()
  1250. moves = receipt.move_ids
  1251. self.env['stock.move.line'].create([{
  1252. 'move_id': move.id,
  1253. 'qty_done': 1,
  1254. 'product_id': product.id,
  1255. 'product_uom_id': product.uom_id.id,
  1256. 'location_id': supplier_location.id,
  1257. 'location_dest_id': input_location.id,
  1258. 'result_package_id': self.env['stock.quant.package'].create({'package_type_id': package_type.id}).id,
  1259. 'picking_id': receipt.id,
  1260. } for product, move in [
  1261. (self.productA, moves[0]),
  1262. (self.productA, moves[0]),
  1263. (self.productB, moves[1]),
  1264. ]])
  1265. receipt.button_validate()
  1266. internal_transfer = receipt.move_ids.move_dest_ids.picking_id
  1267. self.assertRecordValues(internal_transfer.move_line_ids, [
  1268. {'product_id': self.productA.id, 'reserved_uom_qty': 1.0, 'location_dest_id': loc02.id},
  1269. {'product_id': self.productA.id, 'reserved_uom_qty': 1.0, 'location_dest_id': loc03.id},
  1270. {'product_id': self.productB.id, 'reserved_uom_qty': 1.0, 'location_dest_id': loc04.id},
  1271. ])
  1272. def test_rounding_and_reserved_qty(self):
  1273. """
  1274. Basic use case: deliver a storable product put in two packages. This
  1275. test actually ensures that the process 'put in pack' handles some
  1276. possible issues with the floating point representation
  1277. """
  1278. self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 0.4)
  1279. picking = self.env['stock.picking'].create({
  1280. 'picking_type_id': self.warehouse.out_type_id.id,
  1281. 'location_id': self.stock_location.id,
  1282. 'location_dest_id': self.customer_location.id,
  1283. 'move_ids': [(0, 0, {
  1284. 'name': self.productA.name,
  1285. 'product_id': self.productA.id,
  1286. 'product_uom_qty': 0.4,
  1287. 'product_uom': self.productA.uom_id.id,
  1288. 'location_id': self.stock_location.id,
  1289. 'location_dest_id': self.customer_location.id,
  1290. 'picking_type_id': self.warehouse.out_type_id.id,
  1291. })],
  1292. })
  1293. picking.action_confirm()
  1294. picking.move_line_ids.qty_done = 0.3
  1295. picking.action_put_in_pack()
  1296. picking.move_line_ids.filtered(lambda ml: not ml.result_package_id).qty_done = 0.1
  1297. picking.action_put_in_pack()
  1298. quant = self.env['stock.quant'].search([('product_id', '=', self.productA.id), ('location_id', '=', self.stock_location.id)])
  1299. self.assertEqual(quant.available_quantity, 0)
  1300. picking.button_validate()
  1301. self.assertEqual(picking.state, 'done')
  1302. self.assertEqual(picking.move_ids.quantity_done, 0.4)
  1303. self.assertEqual(len(picking.move_line_ids.result_package_id), 2)
  1304. def test_put_out_of_pack_transfer(self):
  1305. """ When a transfer has multiple products all in the same package, removing a product from the destination package
  1306. (i.e. removing it from the package but still putting it in the same location) shouldn't remove it for other products. """
  1307. loc_1 = self.env['stock.location'].create({
  1308. 'name': 'Location A',
  1309. 'location_id': self.stock_location.id,
  1310. })
  1311. loc_2 = self.env['stock.location'].create({
  1312. 'name': 'Location B',
  1313. 'location_id': self.stock_location.id,
  1314. })
  1315. pack = self.env['stock.quant.package'].create({'name': 'New Package'})
  1316. self.env['stock.quant']._update_available_quantity(self.productA, loc_1, 5, package_id=pack)
  1317. self.env['stock.quant']._update_available_quantity(self.productB, loc_1, 4, package_id=pack)
  1318. picking = self.env['stock.picking'].create({
  1319. 'location_id': loc_1.id,
  1320. 'location_dest_id': loc_2.id,
  1321. 'picking_type_id': self.warehouse.int_type_id.id,
  1322. })
  1323. moveA = self.env['stock.move'].create({
  1324. 'name': self.productA.name,
  1325. 'product_id': self.productA.id,
  1326. 'product_uom_qty': 5,
  1327. 'product_uom': self.productA.uom_id.id,
  1328. 'picking_id': picking.id,
  1329. 'location_id': loc_1.id,
  1330. 'location_dest_id': loc_2.id,
  1331. })
  1332. moveB = self.env['stock.move'].create({
  1333. 'name': self.productB.name,
  1334. 'product_id': self.productB.id,
  1335. 'product_uom_qty': 4,
  1336. 'product_uom': self.productB.uom_id.id,
  1337. 'picking_id': picking.id,
  1338. 'location_id': loc_1.id,
  1339. 'location_dest_id': loc_2.id,
  1340. })
  1341. # Check availabilities
  1342. picking.action_assign()
  1343. self.assertEqual(len(moveA.move_line_ids), 1, "A move line should have been created for the reservation of the package.")
  1344. self.assertEqual(moveA.move_line_ids.package_id.id, pack.id, "The package should have been reserved for both products.")
  1345. self.assertEqual(moveB.move_line_ids.package_id.id, pack.id, "The package should have been reserved for both products.")
  1346. pack_level = moveA.move_line_ids.package_level_id
  1347. # Remove the product A from the package in the destination.
  1348. moveA.move_line_ids.result_package_id = False
  1349. self.assertEqual(moveA.move_line_ids.result_package_id.id, False, "No package should be linked in the destination.")
  1350. self.assertEqual(moveA.move_line_ids.package_level_id.id, False, "Package level should have been unlinked from this move line.")
  1351. self.assertEqual(moveB.move_line_ids.result_package_id.id, pack.id, "Package should have stayed the same.")
  1352. self.assertEqual(moveB.move_line_ids.package_level_id.id, pack_level.id, "Package level should have stayed the same.")
  1353. # Validate the picking
  1354. moveA.move_line_ids.qty_done = 5
  1355. moveB.move_line_ids.qty_done = 4
  1356. picking.button_validate()
  1357. # Check that the quants have their expected location/package/quantities
  1358. quantA = self.env['stock.quant'].search([('product_id', '=', self.productA.id), ('location_id', '=', loc_2.id)])
  1359. quantB = self.env['stock.quant'].search([('product_id', '=', self.productB.id), ('location_id', '=', loc_2.id)])
  1360. self.assertEqual(pack.location_id.id, loc_2.id, "Package should have been moved to Location B.")
  1361. self.assertEqual(quantA.quantity, 5, "All 5 units of product A should be in location B")
  1362. self.assertEqual(quantA.package_id.id, False, "There should be no package for product A as it was removed in the move.")
  1363. self.assertEqual(quantB.quantity, 4, "All 4 units of product B should be in location B")
  1364. self.assertEqual(quantB.package_id.id, pack.id, "Product B should still be in the initial package.")