Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
maniamartial committed Jun 20, 2024
1 parent eed0b20 commit 48ae6c9
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,68 +1,3 @@
# import requests
# from ..doctype.custom_exceptions import AuthenticationError, InvoiceCancellationError
# import frappe
# from .base import OBRAPIBase
# from requests.exceptions import RequestException
# import time as time
# from frappe.integrations.utils import make_post_request, make_get_request, create_request_log

# class InvoiceCanceller:

# MAX_RETRIES = 1000
# RETRY_DELAY_SECONDS = 10

# def __init__(self, token):
# obr_base = OBRAPIBase()
# self.BASE_CANCEL_INVOICE_API_URL = obr_base.get_api_from_ebims_settings("cancel_invoice")
# self.token = token

# def _retry_request(self, data, retries):
# try:
# response = requests.post(self.BASE_CANCEL_INVOICE_API_URL, json=data, headers=self._get_headers())
# response.raise_for_status()

# '''Validate the response structure'''
# if not response.json().get("success"):
# raise InvoiceCancellationError(f"Unexpected API response format: {response.text}")

# return response.json()
# except requests.exceptions.RequestException as e:
# error_message = f"Error during API request: {str(e)}"
# frappe.log_error(error_message, "InvoiceCanceller Request Error")
# frappe.log_error(f"Response content: {response.text}")

# '''Resend the cancel invoice request to OBR'''
# if retries > 0:
# frappe.logger().warning(f"Retrying cancel invoice in {self.RETRY_DELAY_SECONDS} seconds... ({self.MAX_RETRIES - retries + 1}/{self.MAX_RETRIES})")
# time.sleep(self.RETRY_DELAY_SECONDS)
# return self._retry_request(data, retries - 1)
# else:
# raise AuthenticationError(f"Max retries reached. {error_message}")

# def _send_request(self, data):
# try:
# return self._retry_request(data, self.MAX_RETRIES)
# except RequestException as e:
# frappe.log_error(f"Error during API request: {str(e)}", title="InvoiceCanceller Request Error")
# raise AuthenticationError(f"Error during API request: {str(e)}")

# def _handle_response(self, response):
# if response.get("success"):
# return response["msg"]
# else:
# raise InvoiceCancellationError(response["msg"])

# def _get_headers(self):
# return {
# "Content-Type": "application/json",
# "Authorization": f"Bearer {self.token}"
# }

# def cancel_invoice(self, data):
# cancel_invoice_data = data
# response = self._send_request(cancel_invoice_data)
# return self._handle_response(response)

import requests
import json
import frappe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def enqueue_retry_posting_sales_invoice(invoice_data, doc_name):
invoice_data=invoice_data,

doc=doc_name,
queue="long",
timeout=300,
queue="short",
timeout=30,
is_async=True,
at_front=False,
)
Expand Down
1 change: 0 additions & 1 deletion burundi_compliance/burundi_compliance/utils/schedular.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def check_and_send_pending_stock_ledger_entry():
check_item = frappe.get_doc("Item", stock_ledger_entry_doc.item_code)
if check_item.custom_allow_obr_to_track_stock_movement == 0:
continue
# frappe.publish_realtime("msgpring",f'{stock_ledger_entry_doc}', user=frappe.session.user)
send_data(stock_ledger_entry_doc)
frappe.db.set_value("Stock Ledger Entry", stock_ledger_entry_doc.name, 'custom_queued', 1)
time.sleep(2)
Expand Down
2 changes: 1 addition & 1 deletion burundi_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
scheduler_events = {

"cron":{
"0 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_sales_invoices"],
"*/5 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_sales_invoices"],
"* * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_stock_ledger_entry"],
},

Expand Down

0 comments on commit 48ae6c9

Please sign in to comment.