|
|
|
@ -61,71 +61,6 @@ def enqueue_sps_sync_order(doc:str):
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
frappe.log_error(title= "Enqueue failed",message =f"{frappe.get_traceback()}")
|
|
|
|
frappe.log_error(title= "Enqueue failed",message =f"{frappe.get_traceback()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @frappe.whitelist(allow_guest=True)
|
|
|
|
|
|
|
|
# def get_sps_sales_order(doc: str):
|
|
|
|
|
|
|
|
# """
|
|
|
|
|
|
|
|
# Calls the SPS API to retrieve a list of all Sales Order URLs.
|
|
|
|
|
|
|
|
# Iterates through the URLs, fetches the corresponding payloads,
|
|
|
|
|
|
|
|
# syncs them into ERPNext, and stores the Sales Order URL paths.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Args:
|
|
|
|
|
|
|
|
# doc (str): The settings document.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Returns:
|
|
|
|
|
|
|
|
# None
|
|
|
|
|
|
|
|
# """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# try:
|
|
|
|
|
|
|
|
# access_token = ""
|
|
|
|
|
|
|
|
# failed_requests = []
|
|
|
|
|
|
|
|
# setting_doc = frappe.get_doc("SPS Integration Settings", doc)
|
|
|
|
|
|
|
|
# SPS_URL = setting_doc.get_sales_order_url
|
|
|
|
|
|
|
|
# expires_on = get_datetime(setting_doc.expires_on)
|
|
|
|
|
|
|
|
# current_time = now_datetime()
|
|
|
|
|
|
|
|
# if expires_on <= current_time or (expires_on - current_time).total_seconds() <= 300:
|
|
|
|
|
|
|
|
# refresh_access_token(setting_doc_name=doc)
|
|
|
|
|
|
|
|
# access_token = setting_doc.get_password("access_token")
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# access_token = setting_doc.get_password("access_token")
|
|
|
|
|
|
|
|
# order_url_path = retrieve_sps_order_urls(setting_doc_name=doc).get("results", [])
|
|
|
|
|
|
|
|
# headers = {
|
|
|
|
|
|
|
|
# "Authorization": f"Bearer {access_token}",
|
|
|
|
|
|
|
|
# "Content-Type": "application/json"
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# # Filtered path url for sales order to avoid duplicates
|
|
|
|
|
|
|
|
# filtered_url_path = exclude_skipped_file_paths(paths=[d.get("path").split("/")[-1] for d in order_url_path])
|
|
|
|
|
|
|
|
# for path in filtered_url_path:
|
|
|
|
|
|
|
|
# # path = record.get("path", "").split("/")[-1]
|
|
|
|
|
|
|
|
# url = f"{SPS_URL}{path}"
|
|
|
|
|
|
|
|
# if url:
|
|
|
|
|
|
|
|
# try:
|
|
|
|
|
|
|
|
# response = requests.get(url=url, headers=headers)
|
|
|
|
|
|
|
|
# if response.status_code == 200:
|
|
|
|
|
|
|
|
# sales_order = create_sps_sales_order(
|
|
|
|
|
|
|
|
# data=response.json(),
|
|
|
|
|
|
|
|
# setting_doc=doc,
|
|
|
|
|
|
|
|
# path=path
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
# if frappe.db.exists("Sales Order", {"name": sales_order, "docstatus":1}):
|
|
|
|
|
|
|
|
# # Once the sales order sync in ERPNext will ack the sales order
|
|
|
|
|
|
|
|
# # sales_order_acknowledgement(data=response.json())
|
|
|
|
|
|
|
|
# path_to_skip = frappe.new_doc("Paths to Skip")
|
|
|
|
|
|
|
|
# path_to_skip.file_path = path
|
|
|
|
|
|
|
|
# path_to_skip.save()
|
|
|
|
|
|
|
|
# frappe.db.commit()
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# failed_requests.append(url)
|
|
|
|
|
|
|
|
# except requests.RequestException as e:
|
|
|
|
|
|
|
|
# frappe.log_error(title="Request Error", message=str(e))
|
|
|
|
|
|
|
|
# api_info = {
|
|
|
|
|
|
|
|
# "Total sales order payload": len(filtered_url_path),
|
|
|
|
|
|
|
|
# "Failed sales order": failed_requests
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# frappe.log_error(title="API Detail Info", message=f"{api_info}")
|
|
|
|
|
|
|
|
# except Exception as e:
|
|
|
|
|
|
|
|
# frappe.log_error(title="Error while sales order sycing", message=f"{frappe.get_traceback()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
|
|
|
def get_sps_sales_order(doc: str):
|
|
|
|
def get_sps_sales_order(doc: str):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|