示例#1
0
def upload_path_handler(instance, filename):
    
    configPart = ConfigPart()

    uploaded_part = FileManagement.validate_folder(configPart.configs.get("UPLOAD_ORDER_PART").data)
    
    return '{uploaded_part}{filename}'.format(uploaded_part=uploaded_part+"/", filename=filename)
示例#2
0
def search_miss_match(request):

    if request.method == 'POST':

        try:
            
            customer_code = request.data['customer_selected']
            project_code = request.data['project_selected']
            supplier_code = request.data['supplier_selected']
            plant_code = request.data['plant_selected']
            start_date = request.data['start_date_selected']
            end_date = request.data['end_date_selected']

            CSV_part_str = FileManagement.validate_folder(configPart.configs.get("MISS_MATCH_ORDER_PART").data)
            CSV_part_generete_str = 'media/' + CSV_part_str + "/"

            orderService = OrderService()
            order_list =  orderService.search_miss_match(customer_code,project_code,supplier_code,plant_code,start_date,end_date)

            order_serializer_list = OrderMissMatchHelper.covert_data_list_to_serializer_list(order_list)

            name_csv_str = "OrderMissMatchCSV_" +datetime.now().strftime("%Y%m%d_%H%M%S")
            CSV_file_management_obj = CSVFileManagement(name_csv_str,CSV_part_generete_str,'',',')
            CSV_file_management_obj.covert_to_header([
                "File ID",
                "Order ID",
                "Supplier",
                "Plant",
                "Part No",
                "Due Date",
                "Order Qty",
                "Pakage No",
                "Pakage Qty",
                "Route&Qty",
                "Uploaded By",
                "Uploaded Date"])
            order_CSV_list = OrderMissMatchHelper.covert_data_list_to_CSV_list(order_list)
            CSV_file_management_obj.covert_to_CSV_data_list(order_CSV_list)
            return_name_CSV_str = CSV_file_management_obj.genearete_CSV_file()
           
            order_serializer = OrderSerializer(order_serializer_list, many=True)

            serializer = serializerMapping.mapping_serializer_list(
                Order_list_Serializer_DTO,
                order_serializer.data,
                "success", 
                "",
                CSV_part_str +"/"+ name_csv_str + ".csv",
                None,
                None )

            return Response(serializer.data, status=status.HTTP_200_OK)

        except Exception as e:

            serializer = serializerMapping.mapping_serializer_list(Order_list_Serializer_DTO,None,"Error",e,None,None,None )

            return Response(serializer.data, status=status.HTTP_200_OK)
示例#3
0
def search_and_print_truck_plan(request):

    if request.method == 'POST':

        try:

            search_and_print_truck_plan_obj = JSONParser().parse(request)
            customer_code = search_and_print_truck_plan_obj[
                'customer_code_selected']
            project_code = search_and_print_truck_plan_obj[
                'project_code_selected']
            due_date_from = search_and_print_truck_plan_obj[
                'due_date_from_selected']
            due_date_to = search_and_print_truck_plan_obj[
                'due_date_to_selected']
            truck_plan_ref = search_and_print_truck_plan_obj['truck_plan_ref']

            CSV_part_str = FileManagement.validate_folder(
                configPart.configs.get("TRUCK_PLAN_TRUCKMANAGEMENT_PART").data)
            CSV_part_generete_str = 'media/' + CSV_part_str + "/"

            truckplan_list = truckPlanManagementService.search_and_print_truck_plan(
                customer_code, project_code, due_date_from, due_date_to,
                truck_plan_ref)

            name_csv_str = "SearchAndPrintTruckPlanCSV_" + datetime.now(
            ).strftime("%Y%m%d_%H%M%S")
            CSV_file_management_obj = CSVFileManagement(
                name_csv_str, CSV_part_generete_str, '', ',')
            CSV_file_management_obj.covert_to_header([
                "Truck Plan Ref.", "PUS Record", "Status", "Due Date",
                "Release Time", "Delivery Time", "Route Code", "Trip",
                "Truck License", "Driver Name"
            ])

            truckplan_CSV_list = TruckplanPrintHelper.covert_data_list_to_CSV_list(
                truckplan_list)
            CSV_file_management_obj.covert_to_CSV_data_list(truckplan_CSV_list)
            return_name_CSV_str = CSV_file_management_obj.genearete_CSV_file()

            serializer_list = TruckplanPrintHelper.covert_data_list_to_serializer_list(
                truckplan_list)

            serializer = serializerMapping.mapping_serializer_list(
                TruckPlan_list_Serializer_DTO, serializer_list, "success", "",
                CSV_part_str + "/" + name_csv_str + '.csv', None, None)

            return Response(serializer.data, status=status.HTTP_200_OK)

        except Exception as e:

            serializer = serializerMapping.mapping_serializer_list(
                TruckPlan_list_Serializer_DTO, None, "Error", e, None, None,
                None)

            return Response(serializer.data, status=status.HTTP_200_OK)
示例#4
0
def search_upload_order_log_file(request):

    if request.method == 'POST':

        try:
            
            customer_code = request.data['customer_selected']
            project_code = request.data['project_selected']
            start_date = request.data['start_date_selected']
            end_date = request.data['end_date_selected']

            CSV_part_str = FileManagement.validate_folder(configPart.configs.get("UPLOAD_LOG_ORDER_PART").data)
            CSV_part_generete_str = 'media/' + CSV_part_str + "/"

            orderService = OrderService()
            file_list =  orderService.search_upload_order_log_file(
                customer_code,
                project_code,
                start_date,
                end_date)

            serializer_list = OrderUploadLogHelper.covert_data_list_to_serializer_list(file_list)

            name_csv_str = "UloadOrderLogFileCSV_" +datetime.now().strftime("%Y%m%d_%H%M%S")
            CSV_file_management_obj = CSVFileManagement(name_csv_str,CSV_part_generete_str,'',',')
            CSV_file_management_obj.covert_to_header([
                "Customer Code",
                "Project",
                "File No",
                "Order Count",
                "Status",
                "Upload By",
                "Upload Date"])
            file_CSV_list = OrderUploadLogHelper.covert_data_list_to_CSV_list(file_list)
            CSV_file_management_obj.covert_to_CSV_data_list(file_CSV_list)
            return_name_CSV_str = CSV_file_management_obj.genearete_CSV_file()

            file_serializer = FileSerializer(serializer_list, many=True)
            serializer = serializerMapping.mapping_serializer_list(
                File_list_Serializer_DTO,
                serializer_list,
                "success", 
                "",
                CSV_part_str + "/" + name_csv_str + ".csv",
                None,
                None )


            return Response(serializer.data, status=status.HTTP_200_OK)

        except Exception as e:

            serializer = serializerMapping.mapping_serializer_list(File_list_Serializer_DTO,None,"Error",e,None,None,None )

            return Response(serializer.data, status=status.HTTP_200_OK)
    def __init__(self, username_str):

        self.file_list = File.objects.filter(updated_by=username_str, status=1)
        self.part_list = Part.objects.filter(is_active=True)
        self.package_list = Package.objects.filter(is_active=True)
        self.routerMaster_list = RouterMaster.objects.filter(is_active=True)
        self.order_list = Order.objects.filter()
        self.project_code = self.file_list[0].project_code

        self.CSV_name_str = settings.MEDIA_ROOT + '/' + FileManagement.find_file(
            configPart.configs.get("UPLOAD_ORDER_PART").data,
            str(self.file_list[0].file_no) + "DatabaseCSV.csv")

        self.updated_by = username_str
示例#6
0
def render_pickup_pdf(request):

    if request.method == 'POST':

        try:

            pickup_data = JSONParser().parse(request)

            PDF_part_str = FileManagement.validate_folder(
                configPart.configs.get("PDF_TRUCKMANAGEMENT_PART").data)
            PDF_part_str = PDF_part_str + "/"

            name_barcode_img_str = "barcode_" + datetime.now().strftime(
                "%Y%m%d_%H%M%S")
            barcode = Barcode(name_barcode_img_str)
            barcode.generate_code128(settings.MEDIA_ROOT + "/" + PDF_part_str,
                                     pickup_data['pickup_no'])

            data_list = truckPlanManagementService.pickup_report(
                pickup_data['pickup_no'])

            context = {
                "pickup_obj": data_list[0][0],
                "order_list": data_list[1],
                "barcode_pic_name": PDF_part_str + name_barcode_img_str
            }
            name_pdf_str = "PickupPDFCSV_" + datetime.now().strftime(
                "%Y%m%d_%H%M%S") + ".pdf"
            html = render_to_string('pdf/pickup_template.html', context)
            PDFManagement.generate_pdf(
                html, settings.MEDIA_ROOT + "/" + PDF_part_str + name_pdf_str,
                link_callback)

            PDF_serializer_DTO = serializerMapping.mapping_pdf(
                PDF_Serializer_DTO, 'success', 'test',
                PDF_part_str + name_pdf_str)

            return JsonResponse(PDF_serializer_DTO.data,
                                status=status.HTTP_200_OK)

        except Exception as e:

            PDF_serializer_DTO = serializerMapping.mapping_pdf(
                PDF_Serializer_DTO, 'Error', e, 'sadasdasd')

            return JsonResponse(PDF_serializer_DTO.data,
                                status=status.HTTP_200_OK)
    def covert_data_list_to_serializer_list(file_list):

        file_return_list = []

        for file_obj in file_list:

            fileSerializer = FileSerializer()
            fileSerializer.customer_code = file_obj[0]
            fileSerializer.project_code = file_obj[1]
            fileSerializer.file_no = file_obj[2]
            fileSerializer.order_count = file_obj[3]
            fileSerializer.status = file_obj[4]
            fileSerializer.updated_by = file_obj[5]
            fileSerializer.updated_date = file_obj[6]
            fileSerializer.csv_url = FileManagement.find_file(
                configPart.configs.get("UPLOAD_ORDER_PART").data,
                file_obj[2] + ".csv")

            file_return_list.append(fileSerializer)

        return file_return_list
示例#8
0
def get_files(request):

    try: 

        if request.method == 'GET':
      
            file_list = File.objects.filter(updated_by= request.user.username, status = 1)

            if len(file_list) > 0 :

                csv_name = FileManagement.find_file(configPart.configs.get("UPLOAD_ORDER_PART").data,file_list[0].file_no+".csv")
                serializer = serializerMapping.mapping_serializer_list(File_list_Serializer_DTO,file_list,"success",None,csv_name,None,None )

            else :

                serializer = serializerMapping.mapping_serializer_list(File_list_Serializer_DTO,[],"success",None,None,None,None )

            return Response(serializer.data,  status=status.HTTP_200_OK)

    except Exception as e:
        
        serializer = serializerMapping.mapping_serializer_list(FileSerializer,None,"Error",e,None,None,None )

        return Response(serializer.data, status=status.HTTP_200_OK)
示例#9
0
    def post(self, request, *args, **kwargs):

        try:
           
            customer_code = request.POST.get("customer_code", "")
            project_code = request.POST.get("project_code", "")

            uploaded_part = FileManagement.validate_folder(configPart.configs.get("UPLOAD_ORDER_PART").data)
            uploaded_part = "media/" + uploaded_part + "/"
            self.order_csv_list_database = []
            self.order_csv_list = []

            file_serializer = FileSerializer(data=request.data)
            
            if file_serializer.is_valid():

                file_obj = file_serializer.save(
                        file_name = request.FILES['file'].name ,
                        file_size = request.FILES['file'].size,
                        updated_by = request.user.username,
                    )
                sheet_obj = WorkbookHelper.read_workbook(file_serializer.data['file'][1:])

                row_max_int = sheet_obj.max_row
                column_max_int = sheet_obj.max_column

                return_list = OrderUploadHelper.data_mapping_from_sheet(sheet_obj)
    
                orderValidatedHelper = OrderValidatedHelper(return_list[0],return_list[3],return_list[4])
                error_list = orderValidatedHelper.get_error_list()
            

                if len(error_list) > 0 :
                    
                    serializer = serializerMapping.mapping_serializer_list(validateErrorSerializerList,None,"Error",configMessage.configs.get("UPLOAD_FILE_MASSAGE_ERROR").data,None,None,sorted(error_list, key=lambda error: (error.row,error.column) ) )
                    File.objects.filter(file_no=file_obj.file_no).delete()
                    return Response(serializer.data, status=status.HTTP_200_OK)

                else :

                    orderManageHelper = OrderManageHelper(file_obj.file_no,return_list[0],return_list[5])
                    orderManageHelper.order_management()
                    name_csv_str = file_obj.file_no + "DatabaseCSV"
                    CSV_file_management_obj = CSVFileManagement(
                        name_csv_str,
                        uploaded_part,
                        '',";")
                    CSV_file_management_obj.covert_to_CSV_data_list(orderManageHelper.get_order_csv_list_database())
                    return_name_CSV_str = CSV_file_management_obj.genearete_CSV_file()

                    name_csv_str = file_obj.file_no
                    CSV_file_management_obj = CSVFileManagement(
                        name_csv_str,
                        uploaded_part,
                        '',',')
                    CSV_file_management_obj.covert_to_header(["Item No","Order ID","Part Number","Part Description","Supplier Name","Plant","Order Amount","Date"])
                    order_csv_list =  orderManageHelper.get_order_csv_list()
                    CSV_file_management_obj.covert_to_CSV_data_list(orderManageHelper.get_order_csv_list())
                    return_name_CSV_str = CSV_file_management_obj.genearete_CSV_file()

                    File.objects.filter(file_no=file_obj.file_no).update(order_count=len(order_csv_list))

                    serializer = serializerMapping.mapping_serializer_list(validateErrorSerializerList,None,"success",configMessage.configs.get("UPLOAD_FILE_MASSAGE_SUCCESSFUL").data,None,None,None )
                    return Response(serializer.data, status=status.HTTP_200_OK)
               
        except Exception as e:

            serializer = serializerMapping.mapping_serializer_list(validateErrorSerializerList,None,"Error",e,None,None,[] )

            return Response(serializer.data, status=status.HTTP_200_OK)