Ejemplo n.º 1
0
    def get_all_products(self, limit, offset):
        client = LazopClient(self.url, self.api_key, self.api_secret)
        request = LazopRequest('/products/get', 'GET')
        request.add_api_param('filter', 'all')
        request.add_api_param('offset', offset)
        request.add_api_param('limit', limit)

        if self.search_item:
            sku_list = json.dumps(self.search_item.split(","))
            frappe.msgprint(str(sku_list))
            request.add_api_param('sku_seller_list', sku_list)

        if self.created_after:
            created_after = datetime.strptime(str(self.created_after),
                                              "%Y-%m-%d").isoformat()
            request.add_api_param('create_after', created_after)

        response = client.execute(request, self.access_token)
        if response.code != '0':
            # frappe.msgprint("Call is not sucessful")
            create_error_log('/products/get', response.code, response.message)
            frappe.msgprint(
                "There is some error while creating Items. Please Check Lazada Error Log!"
            )
            return False
        else:
            # frappe.msgprint(str(response.code))
            # frappe.msgprint(str(response.body))
            if bool(response.body['data']):
                return (response.body['data']['total_products'], response.body)
            else:
                frappe.msgprint("No Item Found to Sync!")
                frappe.db.set_value("Lazada Settings", None, "synced_items", 0)
                return False
Ejemplo n.º 2
0
    def get_oreder_doc(self, order_item_ids):
        client = LazopClient(self.url, self.api_key, self.api_secret)
        request = LazopRequest('/order/document/get', 'GET')
        request.add_api_param('doc_type', 'invoice')
        request.add_api_param('order_item_ids', order_item_ids)

        response = client.execute(request, self.access_token)
        # frappe.msgprint(str(response.type))
        # frappe.msgprint(str(response.body))
        return response.body
Ejemplo n.º 3
0
 def get_order_items(self, order_id):
     client = LazopClient(self.url, self.api_key, self.api_secret)
     request = LazopRequest('/orders/items/get', 'GET')
     request.add_api_param('order_ids', order_id)
     response = client.execute(request, self.access_token)
     if response.code != '0':
         # frappe.msgprint("Call is not sucessful")
         create_error_log('/orders/items/get', response.code,
                          response.message)
         return False
     else:
         # frappe.msgprint(str(response.code))
         # frappe.msgprint(str(response))
         # res_body = response.body
         return response.body
Ejemplo n.º 4
0
 def get_access_token(self):
     client = LazopClient("https://auth.lazada.com/rest", self.api_key,
                          self.api_secret)
     request = LazopRequest('/auth/token/create')
     request.add_api_param("code", self.get_code())
     response = client.execute(request)
     # frappe.msgprint(str(response.body))
     if response.body['code'] != '0':
         frappe.msgprint(
             "Access token is Already Generated. Please Use Refresh Token Button!"
         )
     else:
         frappe.db.set_value("Lazada Settings", None, "access_token",
                             response.body["access_token"])
         frappe.db.set_value("Lazada Settings", None, "refresh_token",
                             response.body['refresh_token'])
         frappe.msgprint(
             "Access Token has been successfully Genrated. Please Reload Page."
         )
Ejemplo n.º 5
0
 def get_refresh_token(self):
     refresh_t = get_pw("Lazada Settings", "refresh_token")
     client = LazopClient("https://auth.lazada.com/rest", self.api_key,
                          self.api_secret)
     request = LazopRequest('/auth/token/refresh')
     request.add_api_param("refresh_token", refresh_t)
     response = client.execute(request)
     # frappe.msgprint(str(response.body))
     # frappe.msgprint(str(now()))
     if response.body['code'] == '0':
         frappe.db.set_value("Lazada Settings", None, "access_token",
                             response.body["access_token"])
         frappe.db.set_value("Lazada Settings", None, "refresh_token",
                             response.body['refresh_token'])
         frappe.db.set_value("Lazada Settings", None,
                             "last_sync_access_token", now())
         frappe.msgprint(
             "Access Token has been refreshed successfully. Please Reload Page!"
         )
     else:
         frappe.msgprint("Error Occured While Refreshing Acces token.")
Ejemplo n.º 6
0
 def get_all_orders(self):
     client = LazopClient(self.url, self.api_key, self.api_secret)
     request = LazopRequest('/orders/get', 'GET')
     if self.last_sync:
         request.add_api_param('created_after', self.last_sync)
     request.add_api_param('status', 'pending')
     request.add_api_param('limit', 99)
     request.add_api_param('sort_direction', 'DESC')
     # frappe.msgprint(str(access_token))
     response = client.execute(request, self.access_token)
     # frappe.msgprint(str(response.type))
     # frappe.msgprint(str(response.body))
     if response.code != '0':
         # frappe.msgprint("Call is not sucessful")
         create_error_log('/orders/get', response.code, response.message)
         return False
     else:
         # frappe.msgprint(str(response.code))
         # frappe.msgprint(str(response.body))
         return response.body
Ejemplo n.º 7
0
 def get_all_transaction(self):
     # frappe.msgprint(str(self.from_date))
     # frappe.throw(str(self.to_date))
     if not self.from_date or not self.to_date:
         frappe.throw(
             "Please Enter <b>From Date</b> and <b>To Date</b> to get Transaction."
         )
     client = LazopClient(self.url, self.api_key, self.api_secret)
     request = LazopRequest('/finance/transaction/detail/get', 'GET')
     request.add_api_param('trans_type', '13')
     request.add_api_param('end_time', str(self.to_date))
     request.add_api_param('start_time', str(self.from_date))
     response = client.execute(request, self.access_token)
     # frappe.msgprint(str(response.type))
     # frappe.msgprint(str(response.body))
     return response.body