示例#1
0
 def get_token(self,cr,uid,ids,context=None):
     if context is None:
         context = {}
     user = self.pool.get('registration.objeto').search_read(cr,uid)#List of users read[]
     obj= self.browse(cr, uid,ids,context)
     if obj.user_id and obj.id_session:
         api = Trading(domain='api.sandbox.ebay.com')
         for i in user:
             if i["user_id"]==obj.user_id:
                 site=i["site"]
                 appid=i["appid"]
                 devid=i["devid"]
                 certid=i["certid"]
             
                 if  site and appid and devid and certid:
                     api.config.set('siteid', site, force=True)
                     api.config.set('appid', appid, force=True)
                     api.config.set('devid', devid, force=True)
                     api.config.set('certid', certid, force=True) 
                     
                     
                     try:
                         response=api.execute("FetchToken",{"SessionID":obj.id_session})
                     except ConnectionError as e:
                         print(e)
                         raise RedirectWarning("Error  obtaning token on eBay, Try it again.\nERROR:%s"%e.message)
                     except ConnectionResponseError as e:
                         raise RedirectWarning("Error response obtaning token to eBay.\n %s"%e.message)
                     else:
                         dic_response=response.dict()
                         ebay_token=dic_response.get("eBayAuthToken")
                     
                     try:
                         response=api.execute('GetTokenStatus')
                     except ConnectionError as e:
                         print(e)
                         print(e.response.dict())
                         raise RedirectWarning("Error to get token status, Try it again.\nERROR:%s"%e.message)
                     except ConnectionResponseError as e:
                         raise RedirectWarning("Error response get token to eBay.\n %s"%e.message)
                     else:
                         status_token= response.dict().get("TokenStatus").get("Status")
                     
                         if status_token=="Active":
                             self.write(cr,uid,ids,{"eBay_Token":ebay_token})
                             this = self.browse(cr, uid, ids)[0]
                             
                             return {'type': 'ir.actions.act_window',
                                 'view_mode': 'tree,form',
                                 'view_type': 'form',
                                 'res_model': 'registration_sign.objeto',
                                 }
                         else:
                             
                             raise RedirectWarning("eBay`s token is incorrect, sign in eBay and create another one new")
                             
                             print "EL TOKEN DEL USUARIO NO ES VALIDO TIENE QUE CAMBIAR DE TOKEN, METASE EN EBAY CREE UNO NUEVO Y VUELVA A INTENTARLO"
         
     else:
         print "GETTOKEN: El Usuario a auntenticar no es el que ha metido no hay obj.user_id o obj.session"
示例#2
0
 def _get_categories(self):  
     list_categories=[]              
     bb=self.env['registration.objeto'].search_read()
     if len(bb)==0:
         if not self.env.context.has_key("check_view_ids"):
             action_id=self.pool['ir.model.data'].get_object_reference(self.env.cr,self.env.context["uid"],'ebaypasoapaso','join_authorize')
             raise RedirectWarning("There is not anyone user register",action_id[1],"Go to create it")
         
     for i in bb:            
            
                  
         #Check if we are upgrading the module, because if not we have a execution fail, because CONTEXTS are different
           
         if self.env.context.has_key("check_view_ids"):
             return list_categories
         else:
             #If user that is surfing, is registered and his session is active
             user_registered=False
             active_sessions=self.env['registration_sign.objeto'].search_read()
             for ses in active_sessions:
                 if ses["eBay_Token"]and ses["actual_state"]=="inside":
                     user_registered=True
                 
             if(self.env.context["uid"]==i["create_uid"][0])and(user_registered):
                 #list_categories=get_categories(i["site"])
                 Data = {            
                     #http://developer.ebay.com/devzone/shopping/docs/callref/types/SiteCodeType.html
                     #'CategorySiteID': site,            
                     #Specifies the maximum depth of the category hierarchy to retrieve, where the top-level categories (meta-categories) are at level 1
                     'LevelLimit': 1,#Default=0
                     'ViewAllNodes':True,
                     'DetailLevel': 'ReturnAll',
                     #'ErrorLanguage':'en_US'#en_US United States, es_ES Spain
                 }
             
                 api = Trading(domain='api.sandbox.ebay.com')
                 site=i["site"]
                 appid=i["appid"]
                 devid=i["devid"]
                 certid=i["certid"]
                 if  site and appid and devid and certid:
                     api.config.set('siteid', site, force=True)
                     api.config.set('appid', appid, force=True)
                     api.config.set('devid', devid, force=True)
                     api.config.set('certid', certid, force=True)
                     
                     try:
                         response = api.execute('GetCategories',Data)
                     except ConnectionError as e:
                         print(e)
                         print(e.response.dict())
                         raise RedirectWarning("Error to get categories on eBay, Try it again.\nERROR:%s"%e.message)
                     except ConnectionResponseError as e:
                         raise RedirectWarning("Error response getting categories token to eBay.\n %s"%e.message)
                     else:
                         d=[]
                         d=response.reply.get('CategoryArray').get('Category')
                         num=0
                         num=int(response.reply.get('CategoryCount'))
                         i=0                
                         while (i<num):
                             list_categories.append((d[i].get('CategoryID'),d[i].get('CategoryName')))
                             i=i+1  
                                           
             else:
                 
                 raise RedirectWarning("You have not got account user or You have not got session initiated")
                 print"GET CATEGORIES:EL UID ACTUAL NO TIENE CUENTA, O NO TIENE SESIÓN INICIADA, COMPRUÉBELO"
                 
             return list_categories
示例#3
0
 def update_product(self,cr,uid,ids,context):
     user=self.browse(cr, uid,ids, context)
     if not user.pictureDetails:
         user.pictureDetails="http://i61.tinypic.com/2qbhqtt.jpg"
     if user.return_accepted=="ReturnsNotAccepted":
         Data={
               "Item":{
                    #http://developer.ebay.com/devzone/xml/docs/Reference/ebay/types/CountryCodeType.html
                   "Country":user.country,
                   "PostalCode":user.postalCode,
                   "currency":user.currency,
                   "PaymentMethods":user.paymentMethods,
                   "ShippingDetails": {
                                       
                                       "ShippingServiceOptions": {
                                                                  "ShippingService": user.shippingservice,
                                                                  "ShippingServiceCost":user.shippingServiceCost
                                                                  }
                                       },
                   "PrimaryCategory":{"CategoryID":user.send_category},#45454
                   #"start_date":user.start_date,
                   "PictureDetails":{"PictureURL": user.pictureDetails},
                   "Description":user.description_article,
                   "ListingDuration":user.listingDuration,
                   "StartPrice":user.startPrice,
                   "Title":user.title,
                   "ConditionID":user.conditionID,
                   "CategoryMappingAllowed": "true",
                   "DispatchTimeMax":"5",
                   "ReturnPolicy": {
                         "ReturnsAcceptedOption": user.return_accepted,
                     }
                   }
             }
     else:
         Data={
               "Item":{
                    #http://developer.ebay.com/devzone/xml/docs/Reference/ebay/types/CountryCodeType.html
                   "Country":user.country,
                   "PostalCode":user.postalCode,
                   "currency":user.currency,
                   "PaymentMethods":user.paymentMethods,
                   "ShippingDetails": {
                                       
                                       "ShippingServiceOptions": {
                                                                  "ShippingService": user.shippingservice,
                                                                  "ShippingServiceCost":user.shippingServiceCost
                                                                  }
                                       },
                   "PrimaryCategory":{"CategoryID":user.send_category},
                   #"start_date":user.start_date,
                   "PictureDetails":{"PictureURL": user.pictureDetails},
                   "Description":user.description_article,
                   "ListingDuration":user.listingDuration,
                   "StartPrice":user.startPrice,
                   "Title":user.title,
                   "ConditionID":user.conditionID,
                   "CategoryMappingAllowed": "true",
                   "DispatchTimeMax":"5",
                   "ReturnPolicy": {
                         "ReturnsAcceptedOption": user.return_accepted,
                         "ReturnsWithinOption": user.whitin,
                         "Description": "If you are not satisfied, return the product for refund.",
                         "ShippingCostPaidByOption":user.who_pay
                     }
                   }
             }
     print user.category
     bb=self.pool.get('registration.objeto').search_read(cr, uid)
     for i in bb:
         user_registered_correct_session=False
         token=""
         active_sessions= self.pool.get('registration_sign.objeto').search_read(cr,uid)#List of users read[]
         for ses in active_sessions:
             if ses["eBay_Token"]and ses["actual_state"]=="inside":
                 
                 timestamp=ses["hour_session"]
                 hour=datetime.now()
                 hour_seg=int(hour.strftime('%s'))
                 
                 tim=hour_seg-timestamp
                 if tim<1200:#If it has not passed more than 1200 seconds, validate session 
                     print "TIME",tim
                     user_registered_correct_session=True
                     token=ses["eBay_Token"]
                     break
                 else:
                     
                     print "INVALID SESSION, You have to come back to SIGN IN"
         if uid==i["create_uid"][0] and user_registered_correct_session:#User has account and is registered, and he has correct session
             api = Trading(domain='api.sandbox.ebay.com')
             site=i["site"]
             appid=i["appid"]
             devid=i["devid"]
             certid=i["certid"]
             if  site and appid and devid and certid and token:
                 
                 api.config.set('siteid', site, force=True)
                 api.config.set('appid', appid, force=True)
                 api.config.set('devid', devid, force=True)
                 api.config.set('certid', certid, force=True)
                 api.config.set("token",token,force=True)
                 
                 try:
                     response = api.execute('AddItem',Data)
                 except ConnectionError as e:
                     print(e)
                     print(e.response.dict())
                     raise RedirectWarning("Error to Add Item on eBay, Try it again.\nERROR:%s"%e.message)
                 except ConnectionResponseError as e:
                         raise RedirectWarning("Error response adding item to eBay.\n %s"%e.message)
                 else:
                 
                     if response.dict().get("ItemID"):
                         print "ITEM VERIFICADO"
                         
                         name=response.dict().get("ItemID")
                         url="http://cgi.sandbox.ebay.es/%s"%name
                         cost=0
                         fee=response.dict().get("Fees").get("Fee")
 
                         i=0
                         while i<len(fee):
                             cost+=float( fee[i].get("Fee").get("value"))
                             i+=1
                         
                         self.write(cr,uid,ids,{
                                                "country":user.country,
                                                "postalCode":user.postalCode,
                                                "site":user.site,
                                                "currency":user.currency,
                                                "paymentMethods":user.paymentMethods,
                                                "category":user.category,
                                                "send_category":user.send_category,
                                                "start_date":user.start_date,
                                                "title":user.title,
                                                "conditionID":user.conditionID,
                                                "pictureDetails":user.pictureDetails,
                                                "description_article":user.description_article,
                                                "listingDuration":user.listingDuration,
                                                "start_Price":user.startPrice,
                                                "shippingServiceCost":user.shippingServiceCost,
                                                "shippingservice":user.shippingservice,
                                                "who_pay":user.who_pay,
                                                "whitin":user.whitin,
                                                "return_accepted":user.return_accepted,
                                                "item_id":name,
                                                "url_id":url,
                                                
 
                                                "actual_state":True,
                                                "cost":cost,
                                                "foot":"env"},context=context)
                         return {
                                 'type': 'ir.actions.act_window',
                                 'view_mode': 'tree,form',
                                 'view_type': 'form',
                                 'res_model': 'add_article.objeto',
                                 
                                 }
                         print "If you are not using a sandbox account, this update  has had a cost of", cost
                         raise RedirectWarning("If you are not using a sandbox account, this update  has had a cost of", cost)
                     else: 
                         print "ITEM INCORRECTO"
                         
                 
         elif uid==i["create_uid"][0]:#If user has not initiated session
             print "User has not initiated session or Session is out of date, it is necessary you initiate it"
             return {
                     'type': 'ir.actions.act_window',
                     'view_mode': 'form',
                     'view_type': 'form',
                     'res_model': 'registration_sign.objeto',
                     }
             
         elif user_registered_correct_session:#If actual user does not have account registered
             print "Actual user does not have account registered, Create it"                        
             return {
                     'name': "New eBay User Authentication",
                     'type': 'ir.actions.act_window',
                     'res_model': 'registration.objeto',
                     'view_mode': 'form',
                     'view_type': 'form',
                     'views': [(False, 'form')],
                     'target': 'new',
                     }
     
     print "UPDATED"
示例#4
0
    def _get_categories(self):
        list_categories = []
        bb = self.env['registration.objeto'].search_read()
        if len(bb) == 0:
            if not self.env.context.has_key("check_view_ids"):
                action_id = self.pool['ir.model.data'].get_object_reference(
                    self.env.cr, self.env.context["uid"], 'ebaypasoapaso',
                    'join_authorize')
                raise RedirectWarning("There is not anyone user register",
                                      action_id[1], "Go to create it")

        for i in bb:

            #Check if we are upgrading the module, because if not we have a execution fail, because CONTEXTS are different

            if self.env.context.has_key("check_view_ids"):
                return list_categories
            else:
                #If user that is surfing, is registered and his session is active
                user_registered = False
                active_sessions = self.env[
                    'registration_sign.objeto'].search_read()
                for ses in active_sessions:
                    if ses["eBay_Token"] and ses["actual_state"] == "inside":
                        user_registered = True

                if (self.env.context["uid"]
                        == i["create_uid"][0]) and (user_registered):
                    #list_categories=get_categories(i["site"])
                    Data = {
                        #http://developer.ebay.com/devzone/shopping/docs/callref/types/SiteCodeType.html
                        #'CategorySiteID': site,
                        #Specifies the maximum depth of the category hierarchy to retrieve, where the top-level categories (meta-categories) are at level 1
                        'LevelLimit': 1,  #Default=0
                        'ViewAllNodes': True,
                        'DetailLevel': 'ReturnAll',
                        #'ErrorLanguage':'en_US'#en_US United States, es_ES Spain
                    }

                    api = Trading(domain='api.sandbox.ebay.com')
                    site = i["site"]
                    appid = i["appid"]
                    devid = i["devid"]
                    certid = i["certid"]
                    if site and appid and devid and certid:
                        api.config.set('siteid', site, force=True)
                        api.config.set('appid', appid, force=True)
                        api.config.set('devid', devid, force=True)
                        api.config.set('certid', certid, force=True)

                        try:
                            response = api.execute('GetCategories', Data)
                        except ConnectionError as e:
                            print(e)
                            print(e.response.dict())
                            raise RedirectWarning(
                                "Error to get categories on eBay, Try it again.\nERROR:%s"
                                % e.message)
                        except ConnectionResponseError as e:
                            raise RedirectWarning(
                                "Error response getting categories token to eBay.\n %s"
                                % e.message)
                        else:
                            d = []
                            d = response.reply.get('CategoryArray').get(
                                'Category')
                            num = 0
                            num = int(response.reply.get('CategoryCount'))
                            i = 0
                            while (i < num):
                                list_categories.append(
                                    (d[i].get('CategoryID'),
                                     d[i].get('CategoryName')))
                                i = i + 1

                else:

                    raise RedirectWarning(
                        "You have not got account user or You have not got session initiated"
                    )
                    print "GET CATEGORIES:EL UID ACTUAL NO TIENE CUENTA, O NO TIENE SESIÓN INICIADA, COMPRUÉBELO"

                return list_categories
示例#5
0
    def update_product(self, cr, uid, ids, context):
        user = self.browse(cr, uid, ids, context)
        if not user.pictureDetails:
            user.pictureDetails = "http://i61.tinypic.com/2qbhqtt.jpg"
        if user.return_accepted == "ReturnsNotAccepted":
            Data = {
                "Item": {
                    #http://developer.ebay.com/devzone/xml/docs/Reference/ebay/types/CountryCodeType.html
                    "Country": user.country,
                    "PostalCode": user.postalCode,
                    "currency": user.currency,
                    "PaymentMethods": user.paymentMethods,
                    "ShippingDetails": {
                        "ShippingServiceOptions": {
                            "ShippingService": user.shippingservice,
                            "ShippingServiceCost": user.shippingServiceCost
                        }
                    },
                    "PrimaryCategory": {
                        "CategoryID": user.send_category
                    },  #45454
                    #"start_date":user.start_date,
                    "PictureDetails": {
                        "PictureURL": user.pictureDetails
                    },
                    "Description": user.description_article,
                    "ListingDuration": user.listingDuration,
                    "StartPrice": user.startPrice,
                    "Title": user.title,
                    "ConditionID": user.conditionID,
                    "CategoryMappingAllowed": "true",
                    "DispatchTimeMax": "5",
                    "ReturnPolicy": {
                        "ReturnsAcceptedOption": user.return_accepted,
                    }
                }
            }
        else:
            Data = {
                "Item": {
                    #http://developer.ebay.com/devzone/xml/docs/Reference/ebay/types/CountryCodeType.html
                    "Country": user.country,
                    "PostalCode": user.postalCode,
                    "currency": user.currency,
                    "PaymentMethods": user.paymentMethods,
                    "ShippingDetails": {
                        "ShippingServiceOptions": {
                            "ShippingService": user.shippingservice,
                            "ShippingServiceCost": user.shippingServiceCost
                        }
                    },
                    "PrimaryCategory": {
                        "CategoryID": user.send_category
                    },
                    #"start_date":user.start_date,
                    "PictureDetails": {
                        "PictureURL": user.pictureDetails
                    },
                    "Description": user.description_article,
                    "ListingDuration": user.listingDuration,
                    "StartPrice": user.startPrice,
                    "Title": user.title,
                    "ConditionID": user.conditionID,
                    "CategoryMappingAllowed": "true",
                    "DispatchTimeMax": "5",
                    "ReturnPolicy": {
                        "ReturnsAcceptedOption": user.return_accepted,
                        "ReturnsWithinOption": user.whitin,
                        "Description":
                        "If you are not satisfied, return the product for refund.",
                        "ShippingCostPaidByOption": user.who_pay
                    }
                }
            }
        print user.category
        bb = self.pool.get('registration.objeto').search_read(cr, uid)
        for i in bb:
            user_registered_correct_session = False
            token = ""
            active_sessions = self.pool.get(
                'registration_sign.objeto').search_read(
                    cr, uid)  #List of users read[]
            for ses in active_sessions:
                if ses["eBay_Token"] and ses["actual_state"] == "inside":

                    timestamp = ses["hour_session"]
                    hour = datetime.now()
                    hour_seg = int(hour.strftime('%s'))

                    tim = hour_seg - timestamp
                    if tim < 1200:  #If it has not passed more than 1200 seconds, validate session
                        print "TIME", tim
                        user_registered_correct_session = True
                        token = ses["eBay_Token"]
                        break
                    else:

                        print "INVALID SESSION, You have to come back to SIGN IN"
            if uid == i["create_uid"][
                    0] and user_registered_correct_session:  #User has account and is registered, and he has correct session
                api = Trading(domain='api.sandbox.ebay.com')
                site = i["site"]
                appid = i["appid"]
                devid = i["devid"]
                certid = i["certid"]
                if site and appid and devid and certid and token:

                    api.config.set('siteid', site, force=True)
                    api.config.set('appid', appid, force=True)
                    api.config.set('devid', devid, force=True)
                    api.config.set('certid', certid, force=True)
                    api.config.set("token", token, force=True)

                    try:
                        response = api.execute('AddItem', Data)
                    except ConnectionError as e:
                        print(e)
                        print(e.response.dict())
                        raise RedirectWarning(
                            "Error to Add Item on eBay, Try it again.\nERROR:%s"
                            % e.message)
                    except ConnectionResponseError as e:
                        raise RedirectWarning(
                            "Error response adding item to eBay.\n %s" %
                            e.message)
                    else:

                        if response.dict().get("ItemID"):
                            print "ITEM VERIFICADO"

                            name = response.dict().get("ItemID")
                            url = "http://cgi.sandbox.ebay.es/%s" % name
                            cost = 0
                            fee = response.dict().get("Fees").get("Fee")

                            i = 0
                            while i < len(fee):
                                cost += float(fee[i].get("Fee").get("value"))
                                i += 1

                            self.write(
                                cr,
                                uid,
                                ids, {
                                    "country": user.country,
                                    "postalCode": user.postalCode,
                                    "site": user.site,
                                    "currency": user.currency,
                                    "paymentMethods": user.paymentMethods,
                                    "category": user.category,
                                    "send_category": user.send_category,
                                    "start_date": user.start_date,
                                    "title": user.title,
                                    "conditionID": user.conditionID,
                                    "pictureDetails": user.pictureDetails,
                                    "description_article":
                                    user.description_article,
                                    "listingDuration": user.listingDuration,
                                    "start_Price": user.startPrice,
                                    "shippingServiceCost":
                                    user.shippingServiceCost,
                                    "shippingservice": user.shippingservice,
                                    "who_pay": user.who_pay,
                                    "whitin": user.whitin,
                                    "return_accepted": user.return_accepted,
                                    "item_id": name,
                                    "url_id": url,
                                    "actual_state": True,
                                    "cost": cost,
                                    "foot": "env"
                                },
                                context=context)
                            return {
                                'type': 'ir.actions.act_window',
                                'view_mode': 'tree,form',
                                'view_type': 'form',
                                'res_model': 'add_article.objeto',
                            }
                            print "If you are not using a sandbox account, this update  has had a cost of", cost
                            raise RedirectWarning(
                                "If you are not using a sandbox account, this update  has had a cost of",
                                cost)
                        else:
                            print "ITEM INCORRECTO"

            elif uid == i["create_uid"][0]:  #If user has not initiated session
                print "User has not initiated session or Session is out of date, it is necessary you initiate it"
                return {
                    'type': 'ir.actions.act_window',
                    'view_mode': 'form',
                    'view_type': 'form',
                    'res_model': 'registration_sign.objeto',
                }

            elif user_registered_correct_session:  #If actual user does not have account registered
                print "Actual user does not have account registered, Create it"
                return {
                    'name': "New eBay User Authentication",
                    'type': 'ir.actions.act_window',
                    'res_model': 'registration.objeto',
                    'view_mode': 'form',
                    'view_type': 'form',
                    'views': [(False, 'form')],
                    'target': 'new',
                }

        print "UPDATED"
示例#6
0
    def get_token(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        user = self.pool.get('registration.objeto').search_read(
            cr, uid)  #List of users read[]
        obj = self.browse(cr, uid, ids, context)
        if obj.user_id and obj.id_session:
            api = Trading(domain='api.sandbox.ebay.com')
            for i in user:
                if i["user_id"] == obj.user_id:
                    site = i["site"]
                    appid = i["appid"]
                    devid = i["devid"]
                    certid = i["certid"]

                    if site and appid and devid and certid:
                        api.config.set('siteid', site, force=True)
                        api.config.set('appid', appid, force=True)
                        api.config.set('devid', devid, force=True)
                        api.config.set('certid', certid, force=True)

                        try:
                            response = api.execute(
                                "FetchToken", {"SessionID": obj.id_session})
                        except ConnectionError as e:
                            print(e)
                            raise RedirectWarning(
                                "Error  obtaning token on eBay, Try it again.\nERROR:%s"
                                % e.message)
                        except ConnectionResponseError as e:
                            raise RedirectWarning(
                                "Error response obtaning token to eBay.\n %s" %
                                e.message)
                        else:
                            dic_response = response.dict()
                            ebay_token = dic_response.get("eBayAuthToken")

                        try:
                            response = api.execute('GetTokenStatus')
                        except ConnectionError as e:
                            print(e)
                            print(e.response.dict())
                            raise RedirectWarning(
                                "Error to get token status, Try it again.\nERROR:%s"
                                % e.message)
                        except ConnectionResponseError as e:
                            raise RedirectWarning(
                                "Error response get token to eBay.\n %s" %
                                e.message)
                        else:
                            status_token = response.dict().get(
                                "TokenStatus").get("Status")

                            if status_token == "Active":
                                self.write(cr, uid, ids,
                                           {"eBay_Token": ebay_token})
                                this = self.browse(cr, uid, ids)[0]

                                return {
                                    'type': 'ir.actions.act_window',
                                    'view_mode': 'tree,form',
                                    'view_type': 'form',
                                    'res_model': 'registration_sign.objeto',
                                }
                            else:

                                raise RedirectWarning(
                                    "eBay`s token is incorrect, sign in eBay and create another one new"
                                )

                                print "EL TOKEN DEL USUARIO NO ES VALIDO TIENE QUE CAMBIAR DE TOKEN, METASE EN EBAY CREE UNO NUEVO Y VUELVA A INTENTARLO"

        else:
            print "GETTOKEN: El Usuario a auntenticar no es el que ha metido no hay obj.user_id o obj.session"
示例#7
0
    def session_id(self, cr, uid, ids, context=None):

        if context is None:
            context = {}

        user = self.pool.get('registration.objeto').search_read(
            cr, uid)  #List of users read[]

        #If there is not user registered
        if len(user) == 0:
            action_id = self.pool['ir.model.data'].get_object_reference(
                cr, uid, 'ebaypasoapaso', 'join_authorize')
            raise RedirectWarning("There is not anyone user register",
                                  action_id[1], "Go to create it")

        num_user = 0
        api = Trading(domain='api.sandbox.ebay.com')
        for i in user:
            obj = self.browse(cr, uid, ids, context)
            num_user += 1

            if i["user_id"] == obj.user_id.strip():

                site = i["site"]
                appid = i["appid"]
                devid = i["devid"]
                certid = i["certid"]
                ru_name = i["ru_name"]

                if appid and devid and certid:
                    api.config.set('siteid', site, force=True)
                    api.config.set('appid', appid, force=True)
                    api.config.set('devid', devid, force=True)
                    api.config.set('certid', certid, force=True)

                    try:
                        response = api.execute('GetSessionID',
                                               {"RuName": ru_name})
                    except ConnectionError as e:
                        print(e)
                        print(e.response.dict())
                        raise RedirectWarning(
                            "Error to get session on eBay, Try it again.\nERROR:%s"
                            % e.message)
                    except ConnectionResponseError as e:
                        raise RedirectWarning(
                            "Error response getting session token to eBay.\n %s"
                            % e.message)
                    else:
                        #For invalidate the session
                        timestamp = parser.parse(
                            (response.dict().get("Timestamp")))
                        timestamp_int = int(timestamp.strftime('%s'))

                        sesion = response.dict().get("SessionID")

                        url = "https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn&runame=%s&SessID=%s" % (
                            ru_name, sesion)

                        self.write(cr,
                                   uid,
                                   ids, {
                                       "site_id": site,
                                       "hour_session": timestamp_int,
                                       "user_id": obj.user_id.strip(),
                                       'id_session': sesion.strip(),
                                       'sign_url': url.strip(),
                                       'actual_state': 'inside'
                                   },
                                   context=context)
                        break
            elif num_user == len(user):
                print num_user
                print len(user)
                print "NO EXISTE NINGUNA CUENTA CON ESE USERID DEBE DARSE DE ALTA"

                action_id = self.pool['ir.model.data'].get_object_reference(
                    cr, uid, 'ebaypasoapaso', 'join_authorize')
                raise RedirectWarning("You have not got account user ",
                                      action_id[1], "Go to create it")
示例#8
0
 def session_id(self,cr, uid, ids, context=None):
     
     if context is None:
         context = {}
     
     user = self.pool.get('registration.objeto').search_read(cr,uid)#List of users read[]
     
     #If there is not user registered  
     if len(user)==0:
         action_id=self.pool['ir.model.data'].get_object_reference(cr,uid,'ebaypasoapaso','join_authorize')
         raise RedirectWarning("There is not anyone user register",action_id[1],"Go to create it")
         
     num_user=0
     api = Trading(domain='api.sandbox.ebay.com')
     for i in user:
         obj= self.browse(cr, uid,ids,context)
         num_user+=1
         
         if i["user_id"]==obj.user_id.strip():
             
             site=i["site"]
             appid=i["appid"]
             devid=i["devid"]
             certid=i["certid"]
             ru_name=i["ru_name"]
            
             if  appid and devid and certid:
                 api.config.set('siteid', site, force=True)
                 api.config.set('appid', appid, force=True)
                 api.config.set('devid', devid, force=True)
                 api.config.set('certid', certid, force=True)
                 
                 try:
                     response=api.execute('GetSessionID',{"RuName":ru_name})
                 except ConnectionError as e:
                     print(e)
                     print(e.response.dict())
                     raise RedirectWarning("Error to get session on eBay, Try it again.\nERROR:%s"%e.message)
                 except ConnectionResponseError as e:
                         raise RedirectWarning("Error response getting session token to eBay.\n %s"%e.message)
                 else:
                     #For invalidate the session
                     timestamp=parser.parse((response.dict().get("Timestamp")))
                     timestamp_int=int(timestamp.strftime('%s'))
                     
                     
                     sesion=response.dict().get("SessionID")
                     
                     url="https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn&runame=%s&SessID=%s"%(ru_name,sesion)
                     
                     self.write(cr, uid, ids, {
                                               "site_id":site,
                                               "hour_session":timestamp_int,
                                               "user_id":obj.user_id.strip(),
                                               'id_session': sesion.strip(),
                                               'sign_url': url.strip(),
                                               'actual_state': 'inside'}, context=context)
                     break;
         elif num_user==len(user):
             print num_user
             print len(user)
             print "NO EXISTE NINGUNA CUENTA CON ESE USERID DEBE DARSE DE ALTA"
             
             action_id=self.pool['ir.model.data'].get_object_reference(cr,uid,'ebaypasoapaso','join_authorize')
             raise RedirectWarning("You have not got account user ",action_id[1],"Go to create it")