test_consume_tracked_component.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from odoo.tests import tagged
  2. from odoo.addons.mrp.tests.common_consume_tracked_component import TestConsumeTrackedComponentCommon
  3. @tagged('post_install', '-at_install')
  4. class TestConsumeTrackedComponent(TestConsumeTrackedComponentCommon):
  5. def test_option_disabled_and_qty_available(self):
  6. """
  7. Option disabled, qty available
  8. -> Not Tracked components are fully consumed
  9. -> Tracked components are only consumed on button_mark_done trigger
  10. """
  11. self.picking_type.use_auto_consume_components_lots = False
  12. mo_none = self.create_mo(self.mo_none_tmpl, self.DEFAULT_AVAILABLE_TRIGGERS_COUNT)
  13. mo_serial = self.create_mo(self.mo_serial_tmpl, self.SERIAL_AVAILABLE_TRIGGERS_COUNT)
  14. mo_lot = self.create_mo(self.mo_lot_tmpl, self.DEFAULT_AVAILABLE_TRIGGERS_COUNT)
  15. mo_all = mo_none + mo_serial + mo_lot
  16. mo_all.action_confirm()
  17. all_qty = 2 * self.DEFAULT_AVAILABLE_TRIGGERS_COUNT + self.SERIAL_AVAILABLE_TRIGGERS_COUNT
  18. quant = self.create_quant(self.raw_none, 3*all_qty)
  19. quant |= self.create_quant(self.raw_lot, 2*all_qty)
  20. quant |= self.create_quant(self.raw_serial, 1*all_qty)
  21. quant.action_apply_inventory()
  22. #Quantities are fully reserved (stock.move state is available)
  23. mo_all.action_assign()
  24. for mov in mo_all.move_raw_ids:
  25. self.assertEqual(mov.product_qty, mov.reserved_availability, "Reserved quantity shall be equal to To Consume quantity.")
  26. #Test for Serial Product
  27. self.executeConsumptionTriggers(mo_serial)
  28. self.executeConsumptionTriggers(mo_none)
  29. self.executeConsumptionTriggers(mo_lot)
  30. for mov in mo_all.move_raw_ids:
  31. if mov.has_tracking == 'none' or mov.raw_material_production_id.state == 'done':
  32. self.assertEqual(mov.product_qty, mov.quantity_done, "Done quantity shall be equal to To Consume quantity.")
  33. else:
  34. self.assertEqual(0, mov.quantity_done, "Done quantity shall be equal to 0.")
  35. def test_option_enabled_and_qty_available(self):
  36. """
  37. Option enabled, qty available
  38. -> Not Tracked components are fully consumed
  39. -> Tracked components are fully consumed
  40. """
  41. mo_none = self.create_mo(self.mo_none_tmpl, self.DEFAULT_AVAILABLE_TRIGGERS_COUNT)
  42. mo_serial = self.create_mo(self.mo_serial_tmpl, self.SERIAL_AVAILABLE_TRIGGERS_COUNT)
  43. mo_lot = self.create_mo(self.mo_lot_tmpl, self.DEFAULT_AVAILABLE_TRIGGERS_COUNT)
  44. mo_all = mo_none + mo_serial + mo_lot
  45. mo_all.action_confirm()
  46. all_qty = 2 * self.DEFAULT_AVAILABLE_TRIGGERS_COUNT + self.SERIAL_AVAILABLE_TRIGGERS_COUNT
  47. quant = self.create_quant(self.raw_none, 3*all_qty)
  48. quant |= self.create_quant(self.raw_lot, 2*all_qty)
  49. quant |= self.create_quant(self.raw_serial, 1*all_qty)
  50. quant.action_apply_inventory()
  51. #Quantities are fully reserved (stock.move state is available)
  52. mo_all.action_assign()
  53. for mov in mo_all.move_raw_ids:
  54. self.assertEqual(mov.product_qty, mov.reserved_availability, "Reserved quantity shall be equal to To Consume quantity.")
  55. self.executeConsumptionTriggers(mo_serial)
  56. self.executeConsumptionTriggers(mo_none)
  57. self.executeConsumptionTriggers(mo_lot)
  58. for mov in mo_all.move_raw_ids:
  59. self.assertEqual(mov.product_qty, mov.quantity_done, "Done quantity shall be equal to To Consume quantity.")
  60. def test_option_enabled_and_qty_not_available(self):
  61. """
  62. Option enabled, qty not available
  63. -> Not Tracked components are fully consumed
  64. -> Tracked components are not consumed
  65. """
  66. mo_none = self.create_mo(self.mo_none_tmpl, self.DEFAULT_TRIGGERS_COUNT)
  67. mo_serial = self.create_mo(self.mo_serial_tmpl, self.SERIAL_TRIGGERS_COUNT)
  68. mo_lot = self.create_mo(self.mo_lot_tmpl, self.DEFAULT_TRIGGERS_COUNT)
  69. mo_all = mo_none + mo_serial + mo_lot
  70. mo_all.action_confirm()
  71. #Quantities are not reserved at all (stock.move state is confirmed)
  72. mo_all.action_assign()
  73. for mov in mo_all.move_raw_ids:
  74. self.assertEqual(0, mov.reserved_availability, "Reserved quantity shall be equal to 0.")
  75. self.executeConsumptionTriggers(mo_serial)
  76. self.executeConsumptionTriggers(mo_none)
  77. self.executeConsumptionTriggers(mo_lot)
  78. for mov in mo_all.move_raw_ids:
  79. if mov.has_tracking == 'none':
  80. self.assertEqual(mov.product_qty, mov.quantity_done, "Done quantity shall be equal to To Consume quantity.")
  81. else:
  82. self.assertEqual(0, mov.quantity_done, "Done quantity shall be equal to To Consume quantity.")
  83. def test_option_enabled_and_qty_partially_available(self):
  84. """
  85. Option enabled, qty partially available
  86. -> Not Tracked components are fully consumed
  87. -> Tracked components are partially consumed
  88. """
  89. #update BoM serial component qty
  90. self.bom_none_lines[2].product_qty = 2
  91. self.bom_serial_lines[2].product_qty = 2
  92. self.bom_lot_lines[2].product_qty = 2
  93. raw_none_qty = 2
  94. raw_tracked_qty = 1
  95. quant = self.create_quant(self.raw_none, raw_none_qty)
  96. quant |= self.create_quant(self.raw_lot, raw_tracked_qty)
  97. quant |= self.create_quant(self.raw_serial, raw_tracked_qty)
  98. quant.action_apply_inventory()
  99. #We must create & process each MO at once as we must assign quants for each individually
  100. def testUnit(mo_tmpl, serialTrigger=None):
  101. mo = self.create_mo(mo_tmpl, 1)
  102. mo.action_confirm()
  103. #Quantities are partially reserved (stock.move state is partially_available)
  104. mo.action_assign()
  105. for mov in mo.move_raw_ids:
  106. if mov.has_tracking == "none":
  107. self.assertEqual(raw_none_qty, mov.reserved_availability, "Reserved quantity shall be equal to " + str(raw_none_qty)+ ".")
  108. else:
  109. self.assertEqual(raw_tracked_qty, mov.reserved_availability, "Reserved quantity shall be equal to " + str(raw_tracked_qty)+ ".")
  110. if serialTrigger is None:
  111. self.executeConsumptionTriggers(mo)
  112. elif serialTrigger == 1:
  113. mo.qty_producing = mo.product_qty
  114. mo._onchange_producing()
  115. elif serialTrigger == 2:
  116. mo.action_generate_serial()
  117. for mov in mo.move_raw_ids:
  118. if mov.has_tracking == "none":
  119. self.assertEqual(mov.product_qty, mov.quantity_done, "Done quantity shall be equal to To Consume quantity.")
  120. else:
  121. self.assertEqual(raw_tracked_qty, mov.quantity_done, "Done quantity shall be equal to " + str(raw_tracked_qty)+ ".")
  122. mo.action_cancel()
  123. testUnit(self.mo_none_tmpl)
  124. testUnit(self.mo_lot_tmpl)
  125. testUnit(self.mo_serial_tmpl, 1)
  126. testUnit(self.mo_serial_tmpl, 2)