def test_load_time_register_duplicates(self): filename = os.path.join(TEST_DATA_PATH, 'maximo_test_time_data.xlsx') excel_data = MaximoExcelData() excel_data.load(filename, MaximoExcelData.LOAD_TIME) results = excel_data.load(filename, MaximoExcelData.LOAD_TIME) self.assertEqual(294, MaximoTimeRegister.objects.count()) self.assertEqual(0, results['time_results']['created']) self.assertEqual(294, results['time_results']['duplicates']) self.assertEqual(294, results['time_results']['rows_parsed']) self.assertEqual(294, len(results['time_results']['errors']))
def handle(self, *args, **options): if options['load_time']: extension = os.path.splitext(options['filename'])[1] if extension == '.xlsx' or extension == '.xls': excel_data = MaximoExcelData(stdout=self.stdout) results = excel_data.load(options['filename'], action=MaximoExcelData.LOAD_TIME) self.stdout.write('Parsed: %s' % options['filename']) self.stdout.write('Created Registers: %d of %d' % (results['time_results']['created'], results['time_results']['rows_parsed'])) elif extension == '.csv': excel_data = MaximoCSVData(stdout=self.stdout) results = excel_data.load_time_registers(options['filename']) self.stdout.write('Parsed: %s' % options['filename']) self.stdout.write('Created Registers: %d of %d' % (results['created'], results['rows_parsed'])) elif options['export_time']: excel_data = MaximoExcelData(stdout=self.stdout) registers = MaximoTimeRegister.objects.all() if options['filename']: filename = options['filename'] else: filename = filename_with_datetime( TEST_OUTPUT_PATH, 'Export_Times_%s.xlsx' % ('TINO')) excel_data.export_time_registers(filename, registers) self.stdout.write('Wrote: %s' % filename) elif options['update_projects']: self.update_projects()
def handle(self, *args, **options): if options['load_time']: extension = os.path.splitext(options['filename'])[1] if extension == '.xlsx' or extension == '.xls': excel_data = MaximoExcelData(stdout=self.stdout) results = excel_data.load(options['filename'], action=MaximoExcelData.LOAD_TIME) self.stdout.write('Parsed: %s' % options['filename']) self.stdout.write('Created Registers: %d of %d' % (results['time_results']['created'], results['time_results']['rows_parsed'])) elif extension == '.csv': excel_data = MaximoCSVData(stdout=self.stdout) results = excel_data.load_time_registers(options['filename']) self.stdout.write('Parsed: %s' % options['filename']) self.stdout.write('Created Registers: %d of %d' % (results['created'], results['rows_parsed'])) elif options['export_time']: excel_data = MaximoExcelData(stdout=self.stdout) registers = MaximoTimeRegister.objects.all() if options['filename']: filename = options['filename'] else: filename = filename_with_datetime(TEST_OUTPUT_PATH, 'Export_Times_%s.xlsx' % ('TINO')) excel_data.export_time_registers(filename, registers) self.stdout.write('Wrote: %s' % filename) elif options['update_projects']: self.update_projects()
def run(self, document_id, load_type, **kwargs): try: document = DataDocument.objects.get(pk=document_id) except: logger.warn('Could not find document with id %d' % document_id) return None data_loader = MaximoExcelData() document.date_start_processing = timezone.now() document.save() try: results = data_loader.load(document.docfile.file, load_type) except Exception as e: msg = 'Error loading file %s. %s: %s' % (document.docfile.name, type(e).__name__, e) logger.error(msg) results = {'fatal_error': msg} document.status = DataDocument.FAILED document.results = results document.date_end_processing = timezone.now() if document.status == DataDocument.PENDING: document.status = DataDocument.PROCESSED document.save() logger.debug('File %s updated to status %s' % (document.docfile.name, document.status)) return results
def test_load_tickets(self): filename = os.path.join(TEST_DATA_PATH, 'maximo_tickets_test_data.xlsx') excel_data = MaximoExcelData() results = excel_data.load(filename, MaximoExcelData.LOAD_TICKETS) self.assertEqual(20, MaximoTicket.objects.count()) self.assertEqual(10, results['ticket_results']['created']) self.assertEqual(0, results['ticket_results']['updated']) self.assertEqual(10, results['ticket_results']['rows_parsed'])
def run(self, document_id, load_type, **kwargs): try: document = DataDocument.objects.get(pk=document_id) except: logger.warn('Could not find document with id %d' % document_id) return None data_loader = MaximoExcelData() document.date_start_processing = timezone.now() document.save() try: results = data_loader.load(document.docfile.file, load_type) except Exception as e: msg = 'Error loading file %s. %s: %s' % (document.docfile.name, type(e).__name__, e) logger.error(msg) results = {'fatal_error': msg } document.status = DataDocument.FAILED document.results = results document.date_end_processing = timezone.now() if document.status == DataDocument.PENDING: document.status = DataDocument.PROCESSED document.save() logger.debug('File %s updated to status %s' % (document.docfile.name, document.status)) return results