def export(self, brand, items=None, item_batch=None, total_failed_on_feed=0): logger.info( "[ExportMemberTempFeed]: Export {0}".format(self.feed_type)) export_status = False client = self.get_client() total_failed = total_failed_on_feed for item in items: logger.info("[ExportMemberTempFeed]: Trying to send SAP the member: {0}"\ .format(item)) try: result = client.service.SI_Mech_Sync( DT_Mac={'item':[item]}, DT_STAMP={'item':item_batch}) logger.info("[ExportMemberTempFeed]: Response from SAP: {0}".format(result)) if result[0]['item'][0]['STATUS'] == 'SUCCESS': try: member_detail = get_model('Member').objects.using(brand).get(mechanic_id=item['TEMP_ID']) member_detail.sent_to_sap = True member_detail.save(using=brand) logger.info("[ExportMemberTempFeed]: Sent the details of member {0} to sap".format(item['TEMP_ID'])) export_status = True except Exception as ex: logger.error("[ExportMemberTempFeed]: Error in member update:{0}::{1}".format(item['TEMP_ID'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportMemberTempFeed]: {0}:: Not received success from sap".format(item['TEMP_ID'])) except Exception as ex: logger.error("[ExportMemberTempFeed]: Error in member update:{0}::{1}".format(item['TEMP_ID'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)
def export(self, brand=None, items=None, item_batch=None, total_failed_on_feed=0): client = self.get_client() total_failed = total_failed_on_feed export_status = False for item in items: logger.error("[ExportCTSFeed]: sending CTS:{0}".format(item['Transaction_Id'])) try: result = client.service.SI_CTS_Sync( DT_CTS_Item={'Item':[item]}, DT_STAMP={'Item_STAMP':item_batch}) logger.info("[ExportCTSFeed]: Response from SAP: {0}".format(result)) if result[0]['STATUS'] == 'SUCCESS': try: cts = get_model('ContainerLR', brand).objects.get(transaction_id=item['Transaction_Id']) cts.sent_to_sap = True cts.save(using=brand) export_status = True except Exception as ex: logger.error("[ExportCTSFeed]: Error in sending CTS:{0}::{1}".format(item['Transaction_Id'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportCTSFeed]: {0}:: Not received success from sap".format(item['Transaction_Id'])) except Exception as ex: logger.error("[ExportCTSFeed]: Error in sending CTS :{0}::{1}".format(item['Transaction_Id'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)+ total_failed_on_feed, failed_data_count=total_failed, success_data_count=len(items) + total_failed_on_feed - total_failed, action='Sent', status=export_status)
def export(self, brand, items=None, item_stamp=None, total_failed_on_feed=0): logger.info( "[ExportRedemptionFeed]: Export {0}".format(self.feed_type)) export_status = False client = self.get_client() total_failed = total_failed_on_feed for item in items: logger.info("[ExportRedemptionFeed]: Trying to send SAP: {0}"\ .format(item)) try: result = client.service.SI_Redum_Sync( DT_Redum={'Item':[item]}, DT_STAMP={'Item':item_stamp}) logger.info("[ExportRedemptionFeed]: Response from SAP: {0}".format(result)) if result[0]['STATUS'] == 'SUCCESS': try: redemption_detail = models.RedemptionRequest.objects.get(transaction_id=item['TRANSID']) redemption_detail.sent_to_sap = True redemption_detail.save() logger.info("[ExportRedemptionFeed]: Sent the details of redemption {0} to sap".format(item['TRANSID'])) export_status = True except Exception as ex: logger.error("[ExportRedemptionFeed]: Error in sending redemption:{0}::{1}".format(item['TRANSID'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportRedemptionFeed]: {0}:: Not received success from sap".format(item['TRANSID'])) except Exception as ex: logger.error("[ExportRedemptionFeed]: Error in sending redemption :{0}::{1}".format(item['TRANSID'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)
def export(self, brand, items=None, item_stamp=None, total_failed_on_feed=0): logger.info( "[ExportAccumulationFeed]: Export {0}".format(self.feed_type)) export_status = False client = self.get_client() total_failed = total_failed_on_feed # item_batch=self.get_chunk(items, settings.BATCH_SIZE) # for item in item_batch: # try: # result = client.service.SI_Acc_Sync( # DT_Accum={'Item':list(item)}, DT_STAMP={'Item_Stamp':item_stamp}) # logger.info("[ExportAccumulationFeed]: Response from SAP: {0}".format(result)) # if result[0]['STATUS'] == 'SUCCESS': # transaction_id_list=[] # for accumulation in item: # transaction_id_list.append(accumulation['TANSSID']) # results = get_model('AccumulationRequest').objects.using(brand).filter(transaction_id__in=transaction_id_list) # results.using(brand).update(sent_to_sap=True) # logger.error("[ExportAccumulationFeed]: Sent details to SAP") # else: # total_failed = total_failed + len(item) # logger.error("[ExportAccumulationFeed]: Not received success from sap") # except Exception as ex: # total_failed = total_failed + len(item) # logger.error("[ExportAccumulationFeed]: Error in sending accumulation :{0}".format(ex)) # feed_log(brand, feed_type=self.feed_type, total_data_count=len(item)\ # + total_failed_on_feed, failed_data_count=total_failed,\ # success_data_count=len(item) + total_failed_on_feed - total_failed,\ # action='Sent', status=export_status) for item in items: logger.info("[ExportAccumulationFeed]: Trying to send SAP the member: {0}"\ .format(item)) try: result = client.service.SI_Acc_Sync( DT_Accum={'Item':[item]}, DT_STAMP={'Item_Stamp':item_stamp}) logger.info("[ExportAccumulationFeed]: Response from SAP: {0}".format(result)) if result[0]['STATUS'] == 'SUCCESS': try: accumulation_detail = models.AccumulationRequest.objects.get(transaction_id=item['TANSSID']) accumulation_detail.sent_to_sap = True accumulation_detail.save() logger.info("[ExportAccumulationFeed]: Sent the details of accumulation {0} to sap".format(item['TANSSID'])) export_status = True except Exception as ex: logger.error("[ExportAccumulationFeed]: Error in sending accumulation:{0}::{1}".format(item['TANSSID'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportAccumulationFeed]: {0}:: Not received success from sap".format(item['TANSSID'])) except Exception as ex: logger.error("[ExportAccumulationFeed]: Error in sending accumulation :{0}::{1}".format(item['TANSSID'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)
def save_to_feed_log(self): failed_feeds=self.failed_feeds remarks = json.dumps(self.remarks) if self.feed_type in ['ECO Implementation Feed', 'ECO Release Feed'] and self.failed_feeds: failed_feeds=self.total_feeds success_data_count = self.total_feeds - failed_feeds path = "" if self.failed_feeds and settings.FEED_FAILURE_MAIL_ENABLED: try: path = self.upload_file(remarks) except Exception as ex : logger.error("Feed file not updated on s3 : %s" % ex) feed_log(brand=settings.BRAND, feed_type=self.feed_type, total_data_count=self.total_feeds, failed_data_count=failed_feeds, success_data_count=success_data_count, status=self.status, action=self.action, remarks=None, file_location=path)
def export(self, brand, items=None, item_batch=None, total_failed_on_feed=0): logger.info( "[ExportCustomerRegistrationFeed]: Export {0}".format(self.feed_type)) client = self.get_client() total_failed = total_failed_on_feed for item in items: export_status = False logger.info("[ExportCustomerRegistrationFeed]: Sending customer - {0}"\ .format(item['CUSTOMER_ID'])) try: # if settings.ENV in ['prod']: # result = client.service.SI_GCPCstID_sync( # item_custveh=[{"item": item}], item=item_batch) # else: result = client.service.SI_CstID_sync( item_custveh=[{"item": item}], item=item_batch) logger.info("[ExportCustomerRegistrationFeed]: Response from SAP: {0}".format(result)) if result[0]['item'][0]['STATUS'] == 'SUCCESS': try: temp_customer_object = models.CustomerTempRegistration.objects.get(temp_customer_id=item['CUSTOMER_ID']) temp_customer_object.sent_to_sap = True # if settings.ENV in ['prod']: # if result[2]: # temp_customer_object.remarks = result[2]['item'][0]['REMARKS'] # else: # temp_customer_object.tagged_sap_id = result[1]['item'][0]['PARTNER'] temp_customer_object.save() export_status = True logger.info("[ExportCustomerRegistrationFeed]: Sent customer ID - {0}".format(item['CUSTOMER_ID'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportCustomerRegistrationFeed]: Error:: {0} - {1}".format(item['CUSTOMER_ID'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportCustomerRegistrationFeed]: Success not received from SAP".format(item['CUSTOMER_ID'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportCustomerRegistrationFeed]: Error:: {0} - {1}".format(item['CUSTOMER_ID'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)
def export_asc_registeration_to_sap(*args, **kwargs): """ send ASC Registration to BAJAJ """ phone_number = kwargs["phone_number"] brand = kwargs["brand"] feed_type = "ASC Registration Feed" status = "success" try: export_obj = export_feed.ExportASCRegistrationFeed( username=settings.SAP_CRM_DETAIL["username"], password=settings.SAP_CRM_DETAIL["password"], wsdl_url=settings.ASC_WSDL_URL, ) feed_export_data = export_obj.export_data(phone_number) export_obj.export(items=feed_export_data["item"], item_batch=feed_export_data["item_batch"]) except Exception as ex: status = "failed" config = settings.REGISTRATION_CONFIG[brand][feed_type] export_asc_registeration_to_sap.retry( exc=ex, countdown=config["retry_time"], kwargs=kwargs, max_retries=config["num_of_retry"] ) finally: export_status = False if status == "failed" else True total_failed = 1 if status == "failed" else 0 if status == "failed": feed_data = "ASC Registration for this %s is failing" % phone_number mail.send_registration_failure(feed_data=feed_data, feed_type="ASC Registration Feed", brand=brand) feed_log( brand, feed_type="ASC Registration Feed", total_data_count=1, failed_data_count=total_failed, success_data_count=1 - total_failed, action="Sent", status=export_status, )
def export(self, brand, items=None, item_batch=None, total_failed_on_feed=0): logger.info( "[ExportCouponRedeemFeed]: Export {0}".format(self.feed_type)) client = self.get_client() total_failed = total_failed_on_feed export_status = False for item in items: export_status = False logger.info("[ExportCouponRedeemFeed]: Sending coupon - {0}"\ .format(item)) try: result = client.service.MI_GCP_UCN_Sync( ITEM=[item], ITEM_BATCH=item_batch) logger.info("[ExportCouponRedeemFeed]: Response from SAP: {0}".format(result)) if result[1]['I_STATUS'] == 'SUCCESS': try: coupon = models.CouponData.objects.get(unique_service_coupon=item['GCP_UCN_NO']) coupon.sent_to_sap = True coupon.save() export_status = True logger.info("[ExportCouponRedeemFeed]: Sent coupon - {0}".format(item['GCP_UCN_NO'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportCouponRedeemFeed]: Error:: {0} - {1}".format(item['GCP_UCN_NO'], ex)) self.feed_remark.fail_remarks(ex) else: total_failed = total_failed + 1 logger.error("[ExportCouponRedeemFeed]: {0}:: Success not received from SAP".format(item['GCP_UCN_NO'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportCouponRedeemFeed]: Error:: {0} - {1}".format(item['GCP_UCN_NO'], ex)) self.feed_remark.fail_remarks(ex) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)
def export(self, brand, items=None, item_batch=None, total_failed_on_feed=0): logger.info( "Export {2}: Items:{0} and Item_batch: {1}"\ .format(items, item_batch, self.feed_type)) client = self.get_client() total_failed = total_failed_on_feed for item in items: export_status = False logger.info("[ExportPurchaseSynFeed]: Sending chassis - {0}"\ .format(item['CHASSIS'])) try: result = client.service.SI_PurchFeed_Sync( DT_Item=[item], DT_STAMP=[{"Item_Stamp":item_batch}]) logger.info("[ExportPurchaseSynFeed]: Response from SAP: {0}".format(result)) if result['STATUS'] == 'SUCCESS': try: vin_sync_feed = models.VinSyncFeedLog.objects.get(product_id = item['CHASSIS']) vin_sync_feed.status_code = result['STATUS'] vin_sync_feed.sent_to_sap = True vin_sync_feed.save() export_status = True logger.info("[ExportPurchaseSynFeed]: Sent the VIN {0} to sap".format(item['CHASSIS'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportPurchaseSynFeed]: Error:: {0} - {1}".format(item['CHASSIS'], ex)) else: total_failed = total_failed + 1 logger.error("[ExportPurchaseSynFeed]:Success not received from SAP {0}".format(item['CHASSIS'])) except Exception as ex: total_failed = total_failed + 1 logger.error("[ExportPurchaseSynFeed]: Error:: {0} - {1}".format(item['CHASSIS'], ex)) feed_log(brand, feed_type=self.feed_type, total_data_count=len(items)\ + total_failed_on_feed, failed_data_count=total_failed,\ success_data_count=len(items) + total_failed_on_feed - total_failed,\ action='Sent', status=export_status)