test_allocation.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # generate_locations.py
  2. import os
  3. import django
  4. import sys
  5. # fun:get_pallet_count_by_batch: 根据托盘码查询批次下托盘总数
  6. # fun:get_location_type: 根据托盘数目获取库位类型
  7. # fun:updata_location_container_link: 更新库位和托盘的关联关系
  8. # fun:get_batch_status: 获取批次状态
  9. # fun:get_batch: 获取批次
  10. # fun:get_location_list_remainder: 获取可用库位的c_number列表
  11. # fun:get_min_list_index: 获取最小的库位
  12. # fun:get_location_by_type_remainder: 根据库位类型获取库位
  13. # fun:get_location_by_type: 第一次入库,根据库位类型获取库位
  14. # fun:get_location_by_status: 根据库位状态获取库位
  15. def setup_django():
  16. # 使用原始字符串处理Windows路径
  17. project_path = "E:/code/greater_wms"
  18. sys.path.append(project_path)
  19. # 根据实际目录名设置(注意下划线)
  20. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'greaterwms.settings')
  21. django.setup()
  22. def main():
  23. try:
  24. # 从正确的应用导入模型
  25. from bin.views import LocationAllocation
  26. # container_code =["12346", "12345", "1", "2", "7"]
  27. container_code =["11111"]
  28. allocator = LocationAllocation() # 创建实例
  29. for code in container_code: # Iterate through each container code
  30. print(f"开始生成库位,托盘编码:{code}")
  31. # allocator.get_location_type(code)
  32. # location_type = allocator.get_location_by_status(code,'in2') # 获取库位类型
  33. # if not location_type:
  34. # print("❌ 库位类型获取失败,请检查托盘数量")
  35. # return
  36. # print(f"库位类型:{location_type}")
  37. number=allocator.get_pallet_count_by_batch(code)
  38. if number is None:
  39. print("❌ 该批次下无托盘,请检查托盘编码")
  40. return
  41. print(f"该批次下托盘总数:{number}")
  42. # # 调用生成方法
  43. # # 修改调用部分的代码
  44. # number=allocator.get_pallet_count_by_batch(container_code) # 通过实例调用)
  45. # if number is None:
  46. # print("❌ 该批次下无托盘,请检查托盘编码")
  47. # return
  48. # print(f"该批次下托盘总数:{number}")
  49. # #
  50. # left_number = allocator.get_left_locationGroup_number_by_type() # 获取每层库位组剩余数量
  51. # if not left_number:
  52. # print("❌ 库位组剩余数量获取失败,请检查库位类型")
  53. # return
  54. # print(f"库位组剩余数量:{left_number}")
  55. # location_type = allocator.get_location_type(number) # 获取库位类型
  56. # if not location_type:
  57. # print("❌ 库位类型获取失败,请检查托盘数量")
  58. # return
  59. # print(f"库位类型:{location_type}")
  60. # # 调用生成库位方法
  61. # batch_status = allocator.get_batch_status(container_code) # 获取批次状态
  62. # if not batch_status:
  63. # print("❌ 批次状态获取失败,请检查批次号")
  64. # return
  65. # print(f"批次状态:{batch_status}")
  66. # batch = allocator.get_batch(container_code)
  67. # if not batch:
  68. # print("❌ 批次获取失败,请检查托盘编码")
  69. # return
  70. # print(f"批次信息:{batch}")
  71. # location_list_cnumber = allocator.get_location_by_status(container_code, 'in2', 1) # 获取库位列表
  72. # if not location_list_cnumber:
  73. # print("❌ 通用库位获取失败,请检查托盘编码")
  74. # return
  75. # print(f"[1]库位:{location_list_cnumber}")
  76. # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd') # 更新库位状态
  77. # if not update_location_status:
  78. # print("❌ 库位状态更新失败,请检查托盘编码")
  79. # return
  80. # print(f"[2]发送任务,库位状态更新成功!")
  81. # update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code) # 更新库位组状态
  82. # if not update_location_group_status:
  83. # print("❌ 库位组状态更新失败,请检查托盘编码")
  84. # return
  85. # print(f"[3]库位组状态更新成功!")
  86. # update_batch_status = allocator.update_batch_status(container_code, '2') # 更新批次状态
  87. # if not update_batch_status:
  88. # print("❌ 批次状态更新失败,请检查批次号")
  89. # return
  90. # print(f"[4]批次状态更新成功!")
  91. # update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code) # 更新库位组的批次
  92. # if not update_location_group_batch:
  93. # print("❌ 库位组批次更新失败,请检查托盘编码")
  94. # return
  95. # print(f"[5]库位组批次更新成功!")
  96. # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied') # 更新库位状态
  97. # if not update_location_status:
  98. # print("❌ 库位状态更新失败,请检查托盘编码")
  99. # return
  100. # print(f"[6]WCS到位,库位状态更新成功!")
  101. # update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code) # 更新库位和托盘的关联关系
  102. # if not update_location_container_link:
  103. # print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
  104. # return
  105. # print(f"[7]库位和托盘的关联关系更新成功!")
  106. # location_list = allocator.get_location_by_type(location_type, 'in2', 1) # 获取库位列表
  107. # if not location_list:
  108. # print("❌ 第一次库位获取失败,请检查库位类型")
  109. # return
  110. # print(f"库位列表:{location_list}")
  111. # location_list_cnumber = allocator.get_location_by_type_remainder(batch, 1) # 获取库位列表
  112. # if not location_list_cnumber:
  113. # print("❌ 剩余库位获取失败,请检查托盘编码")
  114. # return
  115. # print(f"库位列表:{location_list_cnumber}")
  116. print("✅ 方法生成成功!")
  117. except Exception as e:
  118. print(f"❌ 生成失败:{str(e)}")
  119. import traceback
  120. traceback.print_exc()
  121. if __name__ == "__main__":
  122. setup_django()
  123. main()