inbound_task.py 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 = "D:/Document/code/vue/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. from bin.views import LocationAllocation
  25. container_code = "12347"
  26. print(f"开始生成库位,托盘编码:{container_code}")
  27. allocator = LocationAllocation() # 创建实例
  28. location_list_cnumber = allocator.get_location_by_status(container_code, 'in1', 1) # 获取库位列表
  29. if not location_list_cnumber:
  30. print("❌ 通用库位获取失败,请检查托盘编码")
  31. return
  32. print(f"[1]库位:{location_list_cnumber}")
  33. update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd') # 更新库位状态
  34. if not update_location_status:
  35. print("❌ 库位状态更新失败,请检查托盘编码")
  36. return
  37. print(f"[2]发送任务,库位状态更新成功!")
  38. update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code) # 更新库位组状态
  39. if not update_location_group_status:
  40. print("❌ 库位组状态更新失败,请检查托盘编码")
  41. return
  42. print(f"[3]库位组状态更新成功!")
  43. update_batch_status = allocator.update_batch_status(container_code, '2') # 更新批次状态
  44. if not update_batch_status:
  45. print("❌ 批次状态更新失败,请检查批次号")
  46. return
  47. print(f"[4]批次状态更新成功!")
  48. update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code) # 更新库位组的批次
  49. if not update_location_group_batch:
  50. print("❌ 库位组批次更新失败,请检查托盘编码")
  51. return
  52. print(f"[5]库位组批次更新成功!")
  53. update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied') # 更新库位状态
  54. if not update_location_status:
  55. print("❌ 库位状态更新失败,请检查托盘编码")
  56. return
  57. print(f"[6]WCS到位,库位状态更新成功!")
  58. update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code) # 更新库位和托盘的关联关系
  59. if not update_location_container_link:
  60. print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码")
  61. return
  62. print(f"[7]库位和托盘的关联关系更新成功!")
  63. # location_list = allocator.get_location_by_type(location_type, 'in2', 1) # 获取库位列表
  64. # if not location_list:
  65. # print("❌ 第一次库位获取失败,请检查库位类型")
  66. # return
  67. # print(f"库位列表:{location_list}")
  68. # location_list_cnumber = allocator.get_location_by_type_remainder(batch, 1) # 获取库位列表
  69. # if not location_list_cnumber:
  70. # print("❌ 剩余库位获取失败,请检查托盘编码")
  71. # return
  72. # print(f"库位列表:{location_list_cnumber}")
  73. print("✅ 方法生成成功!")
  74. except Exception as e:
  75. print(f"❌ 生成失败:{str(e)}")
  76. import traceback
  77. traceback.print_exc()
  78. if __name__ == "__main__":
  79. setup_django()
  80. main()