def get_response(feed_remark): if feed_remark.failed_feeds > 0: remarks = feed_remark.remarks.elements() for remark in remarks: feed_failure_log(brand=settings.BRAND, feed_type=feed_remark.feed_type, reason=remark) return FAILED else: return SUCCESS
def export(self, data=None): data_source = [] message="some error occurred, please try again later." logger.info( "[ExportUnsyncProductFeed]: Export {1}: Items:{0}"\ .format(data, self.feed_type)) client = self.get_client() logger.info("[ExportUnsyncProductFeed]: sending product details: {0}"\ .format(data['vin'])) result = client.service.SI_GCPONL_Sync( DT_ONL=[{"CHASSIS": data['vin'],"DEALER": data['current_user'].username}]) try: logger.info("[ExportUnsyncProductFeed]: Response from SAP: {0}".format(result)) if len(result)>1: return_code = result[1][0]['RETURN_CODE'] ucn_count = len(result[0]) else: return_code = result[0][0]['RETURN_CODE'] ucn_count=0 if return_code: vin_sync_feed = models.VinSyncFeedLog(product_id = data['vin'], dealer_asc_id=data['current_user'].username, status_code=return_code, ucn_count=ucn_count) vin_sync_feed.save() if return_code.upper() == 'S': message='The Chassis was found in the main database. Please try after sometime.' for results in result[0]: try: valid_dict = { 1 : { "valid_days": 365, "valid_kms": 2000 }, 2 : { "valid_days": 730, "valid_kms": 8000, }, 3 : { "valid_days": 730, "valid_kms": 15000, } } results['DAYS_LIMIT_TO'] = valid_dict[int(results['SERV_TYP'])]['valid_days'] results['KMS_TO'] = valid_dict[int(results['SERV_TYP'])]['valid_kms'] data_source.append(utils.create_dispatch_feed_data(results)) feed_remark = FeedLogWithRemark(len(data_source), feed_type='VIN sync Feed', action='Sent', status=True) except Exception as ex: ex = "[ExportUnsyncProductFeed]: ProductDispatchService: {0} Error on Validating {1}".format(result, ex) feed_remark.fail_remarks(ex) logger.error(ex) feed_remark = save_to_db(feed_type='dispatch', data_source=data_source, feed_remark=feed_remark) feed_remark.save_to_feed_log() if feed_remark.failed_feeds > 0: remarks = feed_remark.remarks.elements() for remark in remarks: feed_failure_log(brand=settings.BRAND, feed_type='VIN sync Feed', reason=remark) logger.info('[ExportUnsyncProductFeed]: ' + json.dumps(feed_remark.remarks)) raise ValueError('dispatch feed failed!') logger.info('[ExportUnsyncProductFeed]: dispatch feed completed') else: message='This Chassis is not available in Main database, please type the correct chassis number' except Exception as ex: logger.error("[ExportUnsyncProductFeed]: Failed to send the details to sap") logger.error(ex) return message