# generate_locations.py import os import django import sys # fun:get_pallet_count_by_batch: 根据托盘码查询批次下托盘总数 # fun:get_location_type: 根据托盘数目获取库位类型 # fun:updata_location_container_link: 更新库位和托盘的关联关系 # fun:get_batch_status: 获取批次状态 # fun:get_batch: 获取批次 # fun:get_location_list_remainder: 获取可用库位的c_number列表 # fun:get_min_list_index: 获取最小的库位 # fun:get_location_by_type_remainder: 根据库位类型获取库位 # fun:get_location_by_type: 第一次入库,根据库位类型获取库位 # fun:get_location_by_status: 根据库位状态获取库位 def setup_django(): # 使用原始字符串处理Windows路径 project_path = "D:/Document/code/vue/greater_wms" sys.path.append(project_path) # 根据实际目录名设置(注意下划线) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'greaterwms.settings') django.setup() def main(): try: # 从正确的应用导入模型 from bin.views import LocationAllocation # container_code =["12346", "12345", "1", "2", "7"] container_code =["11111"] allocator = LocationAllocation() # 创建实例 for code in container_code: # Iterate through each container code print(f"开始生成库位,托盘编码:{code}") # allocator.get_location_type(code) # location_type = allocator.get_location_by_status(code,'in2') # 获取库位类型 # if not location_type: # print("❌ 库位类型获取失败,请检查托盘数量") # return # print(f"库位类型:{location_type}") number=allocator.get_pallet_count_by_batch(code) if number is None: print("❌ 该批次下无托盘,请检查托盘编码") return print(f"该批次下托盘总数:{number}") # # 调用生成方法 # # 修改调用部分的代码 # number=allocator.get_pallet_count_by_batch(container_code) # 通过实例调用) # if number is None: # print("❌ 该批次下无托盘,请检查托盘编码") # return # print(f"该批次下托盘总数:{number}") # # # left_number = allocator.get_left_locationGroup_number_by_type() # 获取每层库位组剩余数量 # if not left_number: # print("❌ 库位组剩余数量获取失败,请检查库位类型") # return # print(f"库位组剩余数量:{left_number}") # location_type = allocator.get_location_type(number) # 获取库位类型 # if not location_type: # print("❌ 库位类型获取失败,请检查托盘数量") # return # print(f"库位类型:{location_type}") # # 调用生成库位方法 # batch_status = allocator.get_batch_status(container_code) # 获取批次状态 # if not batch_status: # print("❌ 批次状态获取失败,请检查批次号") # return # print(f"批次状态:{batch_status}") # batch = allocator.get_batch(container_code) # if not batch: # print("❌ 批次获取失败,请检查托盘编码") # return # print(f"批次信息:{batch}") # location_list_cnumber = allocator.get_location_by_status(container_code, 'in2', 1) # 获取库位列表 # if not location_list_cnumber: # print("❌ 通用库位获取失败,请检查托盘编码") # return # print(f"[1]库位:{location_list_cnumber}") # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'reserverd') # 更新库位状态 # if not update_location_status: # print("❌ 库位状态更新失败,请检查托盘编码") # return # print(f"[2]发送任务,库位状态更新成功!") # update_location_group_status = allocator.update_location_group_status(location_list_cnumber.location_code) # 更新库位组状态 # if not update_location_group_status: # print("❌ 库位组状态更新失败,请检查托盘编码") # return # print(f"[3]库位组状态更新成功!") # update_batch_status = allocator.update_batch_status(container_code, '2') # 更新批次状态 # if not update_batch_status: # print("❌ 批次状态更新失败,请检查批次号") # return # print(f"[4]批次状态更新成功!") # update_location_group_batch = allocator.update_location_group_batch(location_list_cnumber, container_code) # 更新库位组的批次 # if not update_location_group_batch: # print("❌ 库位组批次更新失败,请检查托盘编码") # return # print(f"[5]库位组批次更新成功!") # update_location_status = allocator.update_location_status(location_list_cnumber.location_code, 'occupied') # 更新库位状态 # if not update_location_status: # print("❌ 库位状态更新失败,请检查托盘编码") # return # print(f"[6]WCS到位,库位状态更新成功!") # update_location_container_link = allocator.update_location_container_link(location_list_cnumber.location_code, container_code) # 更新库位和托盘的关联关系 # if not update_location_container_link: # print("❌ 库位和托盘的关联关系更新失败,请检查托盘编码") # return # print(f"[7]库位和托盘的关联关系更新成功!") # location_list = allocator.get_location_by_type(location_type, 'in2', 1) # 获取库位列表 # if not location_list: # print("❌ 第一次库位获取失败,请检查库位类型") # return # print(f"库位列表:{location_list}") # location_list_cnumber = allocator.get_location_by_type_remainder(batch, 1) # 获取库位列表 # if not location_list_cnumber: # print("❌ 剩余库位获取失败,请检查托盘编码") # return # print(f"库位列表:{location_list_cnumber}") print("✅ 方法生成成功!") except Exception as e: print(f"❌ 生成失败:{str(e)}") import traceback traceback.print_exc() if __name__ == "__main__": setup_django() main()