def get_report_list(self, report_rec): seller = report_rec.seller_id if not seller: raise Warning('Please select seller') proxy_data = seller.get_proxy_server() mws_obj = Reports(access_key=str(seller.access_key), secret_key=str(seller.secret_key), account_id=str(seller.merchant_id), region=seller.country_id.amazon_marketplace_code or seller.country_id.code, proxies=proxy_data) if not report_rec.request_id: return True try: result = mws_obj.get_report_list( requestids=[report_rec.request_id]) self.update_report_history(report_rec, result) except Exception, e: if hasattr(mws_obj, 'parsed_response_error') and type( mws_obj.parsed_response_error) != type(None): error = mws_obj.parsed_response_error.parsed or {} error_value = error.get('Message', {}).get('value') error_value = error_value if error_value else str( mws_obj.response.content) else: error_value = str(e) raise Warning(error_value)
def request_report(self): instance = self.instance_id seller = self.instance_id.seller_id report_type = self.report_type if not seller: raise Warning('Please select instance') proxy_data = seller.get_proxy_server() mws_obj = Reports(access_key=str(seller.access_key), secret_key=str(seller.secret_key), account_id=str(seller.merchant_id), region=seller.country_id.amazon_marketplace_code or seller.country_id.code, proxies=proxy_data) marketplace_ids = tuple([instance.market_place_id]) try: result = mws_obj.request_report(report_type, start_date=None, end_date=None, marketplaceids=marketplace_ids) self.update_report_history(result) except Exception, e: if hasattr(mws_obj, 'parsed_response_error') and type( mws_obj.parsed_response_error) != type(None): error = mws_obj.parsed_response_error.parsed or {} error_value = error.get('Message', {}).get('value') error_value = error_value if error_value else str( mws_obj.response.content) else: error_value = str(e) raise Warning(error_value)
def request_report(self, report_rec, seller, report_type, start_date, end_date): if not seller: raise Warning('Please select instance') if start_date: db_import_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S", db_import_time) start_date = time.strftime( "%Y-%m-%dT%H:%M:%S", time.gmtime( time.mktime( time.strptime(db_import_time, "%Y-%m-%dT%H:%M:%S")))) start_date = str(start_date) + 'Z' else: today = datetime.now() earlier = today - timedelta(days=30) earlier_str = earlier.strftime("%Y-%m-%dT%H:%M:%S") start_date = earlier_str + 'Z' if end_date: db_import_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S", db_import_time) end_date = time.strftime( "%Y-%m-%dT%H:%M:%S", time.gmtime( time.mktime( time.strptime(db_import_time, "%Y-%m-%dT%H:%M:%S")))) end_date = str(end_date) + 'Z' else: today = datetime.now() earlier_str = today.strftime("%Y-%m-%dT%H:%M:%S") end_date = earlier_str + 'Z' proxy_data = seller.get_proxy_server() mws_obj = Reports(access_key=str(seller.access_key), secret_key=str(seller.secret_key), account_id=str(seller.merchant_id), region=seller.country_id.amazon_marketplace_code or seller.country_id.code, proxies=proxy_data) instances = self.env['amazon.instance.ept'].search([('seller_id', '=', seller.id)]) marketplaceids = tuple(map(lambda x: x.market_place_id, instances)) try: result = mws_obj.request_report(report_type, start_date=start_date, end_date=end_date, marketplaceids=marketplaceids) self.update_report_history(report_rec, result) except Exception, e: if hasattr(mws_obj, 'parsed_response_error') and type( mws_obj.parsed_response_error) != type(None): error = mws_obj.parsed_response_error.parsed or {} error_value = error.get('Message', {}).get('value') error_value = error_value if error_value else str( mws_obj.response.content) else: error_value = str(e) raise Warning(error_value)
def get_reports(self): self.ensure_one() seller = self.seller_id if not seller: raise Warning('Please select seller') start_date = self.start_date end_date = self.end_date if start_date: db_import_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S", db_import_time) start_date = time.strftime( "%Y-%m-%dT%H:%M:%S", time.gmtime( time.mktime( time.strptime(db_import_time, "%Y-%m-%dT%H:%M:%S")))) start_date = str(start_date) + 'Z' else: today = datetime.now() earlier = today - timedelta(days=30) earlier_str = earlier.strftime("%Y-%m-%dT%H:%M:%S") start_date = earlier_str + 'Z' if end_date: db_import_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S", db_import_time) end_date = time.strftime( "%Y-%m-%dT%H:%M:%S", time.gmtime( time.mktime( time.strptime(db_import_time, "%Y-%m-%dT%H:%M:%S")))) end_date = str(end_date) + 'Z' else: today = datetime.now() earlier_str = today.strftime("%Y-%m-%dT%H:%M:%S") end_date = earlier_str + 'Z' mws_obj = Reports(access_key=str(seller.access_key), secret_key=str(seller.secret_key), account_id=str(seller.merchant_id), region=seller.country_id.amazon_marketplace_code or seller.country_id.code) try: result = mws_obj.get_report_list(types=(self.report_type, ), fromdate=start_date, todate=end_date) except Exception, e: if hasattr(mws_obj, 'parsed_response_error') and type( mws_obj.parsed_response_error) != type(None): error = mws_obj.parsed_response_error.parsed or {} error_value = error.get('Message', {}).get('value') error_value = error_value if error_value else str( mws_obj.response.content) else: error_value = str(e) raise Warning(error_value)