コード例 #1
0
    def postDistributor(ObjectList, Credential):
        distributor_list = []
        feed_remark = FeedLogWithRemark(
            len(ObjectList.DistributorData), feed_type="Distributor Feed", action="Received", status=True
        )
        for distributor in ObjectList.DistributorData:
            try:
                distributor_list.append(
                    {
                        "id": distributor.DISTRIBUTOR_ID.upper(),
                        "name": distributor.NAME.upper(),
                        "email": distributor.EMAIL,
                        "mobile": utils.mobile_format(distributor.PHONE_NUMBER),
                        "city": distributor.CITY.upper(),
                        "asm_id": distributor.ASM_ID,
                    }
                )
            except Exception as ex:
                ex = "DistributorService: {0}  Error on Validating {1}".format(distributor, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type="distributor", data_source=distributor_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #2
0
    def postMechanic(ObjectList, Credential):
        mechanic_list = []
        feed_remark = FeedLogWithRemark(
            len(ObjectList.MechanicData), feed_type="Mechanic Feed", action="Received", status=True
        )
        for mechanic in ObjectList.MechanicData:
            try:
                mechanic_list.append(
                    {
                        "mechanic_id": mechanic.MECH_ID,
                        #                     'first_name': mechanic.FIRST_NAME,
                        #                     'last_name': mechanic.LAST_NAME,
                        #                     'mobile': utils.mobile_format(mechanic.PHONE_NUMBER),
                        #                     'shop_name': mechanic.SHOP_NAME,
                        #                     'dob': mechanic.DOB,
                        #                     'district': mechanic.DISTRICT,
                        #                     'state': mechanic.STATE,
                        #                     'pincode': mechanic.PINCODE,
                        #                     'dist_id': mechanic.DIST_ID,
                        "temp_id": mechanic.TEMP_MECH_ID,
                    }
                )
            except Exception as ex:
                ex = "MechanicService: {0}  Error on Validating {1}".format(mechanic, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type="mechanic", data_source=mechanic_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #3
0
    def postProductPurchase(ObjectList, Credential):
        feed_remark = FeedLogWithRemark(len(ObjectList.ProductPurchaseData),
                                        feed_type='Purchase Feed',
                                        action='Received', status=True)
        product_purchase_list = []
        for product in ObjectList.ProductPurchaseData:
            try:
                product_purchase_list.append({
                    'vin': product.CHASSIS,
                    'sap_customer_id': product.CUSTOMER_ID,
                    'customer_phone_number': utils.mobile_format(product.CUST_MOBILE),
                    'customer_name': product.CUSTOMER_NAME,
                    'city': product.CITY,
                    'state': product.STATE,
                    'pin_no': product.PIN_NO,
                    'product_purchase_date': product.VEH_SL_DT,
                    'engine': product.ENGINE,
                    'veh_reg_no': product.VEH_REG_NO
                })
            except Exception as ex:
                ex = "ProductPurchaseService: {0}  Error on Validating {1}".format(product, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)

        feed_remark = save_to_db(
            feed_type='purchase', data_source=product_purchase_list,
                                                 feed_remark=feed_remark)
        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #4
0
    def postPartPoint(ObjectList, Credential):
        part_upc_list = []
        feed_remark = FeedLogWithRemark(
            len(ObjectList.PartPointData), feed_type="Part points Feed", action="Received", status=True
        )
        for part in ObjectList.PartPointData:
            try:
                part_upc_list.append(
                    {
                        "part_number": part.PART_NUMBER,
                        "points": part.POINTS,
                        "price": part.PRICE,
                        "mrp": part.MRP,
                        "valid_from": part.VALID_FROM,
                        "valid_to": part.VALID_TILL,
                        "territory": part.TERRITORY,
                    }
                )
            except Exception as ex:
                ex = "PartPointService: {0}  Error on Validating {1}".format(part, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type="part_point", data_source=part_upc_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #5
0
    def postPartMaster(ObjectList, Credential):
        try:
            part_master_list = []
            feed_remark = FeedLogWithRemark(
                len(ObjectList.PartMasterData), feed_type="Part Master Feed", action="Received", status=True
            )

            for part in ObjectList.PartMasterData:
                part_master_list.append(
                    {
                        "part_number": part.PART_NUMBER,
                        "part_model": part.PART_MODEL,
                        "part_type": part.PART_TYPE,
                        "category": part.CATEGORY,
                        "description": part.DESCRIPTION,
                        "segment": part.SEGMENT,
                        "supplier": part.SUPPLIER,
                    }
                )
        except Exception as ex:
            ex = "PartMasterService: {0}  Error on Validating {1}".format(part, ex)
            feed_remark.fail_remarks(ex)
            logger.error(ex)
        feed_remark = save_to_db(feed_type="part_master", data_source=part_master_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #6
0
    def postDealer(ObjectList, Credential):
        dealer_list = []
        feed_remark = FeedLogWithRemark(len(ObjectList.DealerData),
                                        feed_type='Dealer Feed',
                                        action='Received', status=True)
        for dealer in ObjectList.DealerData:
            try:
                dealer_list.append({
                    'id': dealer.KUNNR,
                    'address': dealer.ADDRESS,
                    'service_advisor_id': dealer.SER_ADV_ID,
                    'name': dealer.SER_ADV_NAME,
                    'phone_number': utils.mobile_format(dealer.SER_ADV_MOBILE),
                    'status': dealer.ACTIVE_FLAG,
                    'cdms_flag':dealer.CDMS_FLAG
                })
            except Exception as ex:
                ex = "DealerService: {0}  Error on Validating {1}".format(dealer, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type='dealer', data_source=dealer_list,
                              feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #7
0
    def postProductDispatch(ObjectList, Credential):
        feed_remark = FeedLogWithRemark(len(ObjectList.ProductDispatchData),
                                        feed_type='Dispatch Feed',
                                        action='Received', status=True)
        product_dispatch_list = []
        for product in ObjectList.ProductDispatchData:
            try:
                product_dispatch_list.append({
                    'vin': product.CHASSIS,
                    'product_type': product.PRODUCT_TYPE,
                    'invoice_date': product.VEC_DIS_DT,
                    'dealer_id': product.KUNNR,
                    'unique_service_coupon': product.UCN_NO,
                    'valid_days': product.DAYS_LIMIT_TO,
                    'valid_kms': product.KMS_TO,
                    'service_type': product.SERVICE_TYPE,
                    'coupon_status': settings.DEFAULT_COUPON_STATUS,
#                     'sku_code':product.SKU_CODE
#                     'engine':product.ENGINE,
                })
            except Exception as ex:
                ex = "ProductDispatchService: {0}  Error on Validating {1}".format(product, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)

        feed_remark = save_to_db(
            feed_type='dispatch', data_source=product_dispatch_list,
                                        feed_remark=feed_remark)
        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #8
0
    def postPartUPC(ObjectList, Credential):
        part_point_list = []
        feed_remark = FeedLogWithRemark(
            len(ObjectList.PartUPCData), feed_type="Part UPC Feed", action="Received", status=True
        )
        for part in ObjectList.PartUPCData:
            try:
                part_point_list.append({"part_number": part.PART_NUMBER, "UPC": part.PART_UPC})
            except Exception as ex:
                ex = "PartUPCService: {0}  Error on Validating {1}".format(part, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type="part_upc", data_source=part_point_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #9
0
    def postNSM(ObjectList, Credential):
        nsm_list = []
        feed_remark = FeedLogWithRemark(len(ObjectList.NSMData), feed_type="NSM Feed", action="Received", status=True)
        for nsm in ObjectList.NSMData:
            try:
                nsm_list.append(
                    {
                        "name": nsm.NAME,
                        "email": nsm.EMAIL,
                        "phone_number": utils.mobile_format(nsm.PHONE_NUMBER),
                        "territory": nsm.TERRITORY,
                    }
                )
            except Exception as ex:
                ex = "NSMService: {0}  Error on Validating {1}".format(nsm, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        feed_remark = save_to_db(feed_type="nsm", data_source=nsm_list, feed_remark=feed_remark)

        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #10
0
    def postCreditNote(ObjectList, Credential):
        feed_remark = FeedLogWithRemark(len(ObjectList.CreditNoteData),
                                        feed_type='Credit Note Feed',
                                        action='Received', status=True)
        cdms_feed_remark = FeedLogWithRemark(len(ObjectList.CreditNoteData),
                                        feed_type='CDMS Feed',
                                        action='Received', status=True)
        credit_note_list = []
        for credit_note in ObjectList.CreditNoteData:
            try:
                credit_note_list.append({
                    'vin': credit_note.CHASSIS,
                    'dealer': credit_note.GCP_KUNNR,
                    'actual_kms': credit_note.GCP_KMS,
                    'unique_service_coupon': credit_note.GCP_UCN_NO,
                    'service_type': credit_note.SERVICE_TYPE,
                    'actual_service_date': credit_note.SER_AVL_DT,
                    'received_date': credit_note.GCPDATA_RECV_DT,
                    'credit_note': credit_note.CREDIT_NOTE,
                    'credit_date': credit_note.CREDIT_DATE,
                    'cdms_doc_number': credit_note.CDMS_DOC_NO,
                    'cdms_date': credit_note.CDMS_DT
#                    'closed_date': credit_note.CLOSED_DATE
                })

            except Exception as ex:
                ex = "CreditNoteService: {0} Error on Validating {1}".format(credit_note, ex)
                feed_remark.fail_remarks(ex)
                logger.error(ex)
        if credit_note.CDMS_DOC_NO:
            feed_remark = save_to_db(
                                    feed_type='credit_note', data_source=credit_note_list,
                                        feed_remark=cdms_feed_remark)
        else:
            feed_remark = save_to_db(
            feed_type='credit_note', data_source=credit_note_list,
                                        feed_remark=feed_remark)
        feed_remark.save_to_feed_log()
        return get_response(feed_remark)
コード例 #11
0
 def postASC(ObjectList, Credential):
     asc_list = []
     feed_remark = FeedLogWithRemark(len(ObjectList.ASCData),
                                     feed_type='ASC Feed',
                                     action='Received', status=True)
     for asc_element in ObjectList.ASCData:
         try:
             asc_list.append({
                 'asc_id': asc_element.ASC_ID,
                 'name': asc_element.ASC_NAME,
                 'phone_number': utils.mobile_format(asc_element.ASC_MOBILE),
                 'address': asc_element.ASC_ADDRESS,
                 'email': asc_element.ASC_EMAIL,
                 'dealer_id': asc_element.KUNNAR
             })
         except Exception as ex:
             ex = "ASCService: {0}  Error on Validating {1}".format(asc_element, ex)
             feed_remark.fail_remarks(ex)
             logger.error(ex)
     feed_remark = save_to_db(feed_type='ASC', data_source=asc_list,
                           feed_remark=feed_remark)
     feed_remark.save_to_feed_log()
     return get_response(feed_remark)    
コード例 #12
0
 def postOldFsc(ObjectList, Credential):
     feed_remark = FeedLogWithRemark(len(ObjectList.OldFSCData.GT_OLD_FSC),
                                     feed_type='Old Fsc Feed',
                                     action='Received', status=True)
     old_fsc_list = []
     for fsc in ObjectList.OldFSCData.GT_OLD_FSC:
         try:
             old_fsc_list.append({
                 'vin': fsc.CHASSIS,
                 'dealer': fsc.KUNNAR,
                 'material_number': fsc.MATNR,
                 'charge': fsc.CHARG,
                 'service': fsc.SERVICE
             })
           
         except Exception as ex:
             ex = "OldFscUpdateService: {0}  Error on Validating {1}".format(fsc, ex)
             feed_remark.fail_remarks(ex)
             logger.error(ex)
     feed_remark = save_to_db(
         feed_type='old_fsc', data_source=old_fsc_list,
                                              feed_remark=feed_remark)
     feed_remark.save_to_feed_log()
     return get_response(feed_remark)
コード例 #13
0
    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
コード例 #14
0
class ExportCouponRedeemFeed(BaseExportFeed):
    
    def export_data(self, start_date=None, end_date=None):
        results = models.CouponData.objects.filter(sent_to_sap=0,
                            status=2).select_related('product_id')
        items = []
        total_failed = 0
        item_batch = {
            'TIMESTAMP': datetime.now().strftime("%Y-%m-%dT%H:%M:%S")}
        self.feed_remark = FeedLogWithRemark(len(results), feed_type='Coupon Redemption Feed', action='Send', status=True)
        for redeem in results:
            try:
                #added the condition only for the previous coupons with no servicing dealer details
                if redeem.service_advisor:
                    if redeem.service_advisor.dealer:
                        servicing_dealer = redeem.service_advisor.dealer.dealer_id
                    else:
                        servicing_dealer = redeem.service_advisor.asc.asc_id
                else:
                    servicing_dealer = redeem.product.dealer_id.dealer_id
                
                item = {
                        "CHASSIS": redeem.product.product_id,
                        "GCP_KMS": redeem.actual_kms,
                        "GCP_KUNNR": servicing_dealer,
                        "GCP_UCN_NO": redeem.unique_service_coupon,
                        "PRODUCT_TYPE": redeem.product.sku_code,
                        "SERVICE_TYPE": str(redeem.service_type),
                        "SER_AVL_DT": redeem.actual_service_date.date().strftime("%Y-%m-%d"),
                    }                        
                items.append(item)
            except Exception as ex:
                logger.error("[ExportCouponRedeemFeed]: error fetching from db {0}".format(ex))
                total_failed = total_failed + 1
                self.feed_remark.fail_remarks(ex)
        logger.info("[ExportCouponRedeemFeed]: processed coupon")
        return items, item_batch, total_failed

    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)