Skip to content

Commit

Permalink
Feat: Implemented stock movement search etims endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
GichanaMayaka committed Apr 11, 2024
1 parent 4a50ea8 commit 738107c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
46 changes: 46 additions & 0 deletions kenya_compliance/kenya_compliance/apis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,52 @@ def perform_code_search(request_data: str) -> None:
frappe.throw("Timeout Encountered", error, title="Timeout Error")


@frappe.whitelist()
def perform_stock_movement_search(request_data: str) -> None:
data = json.loads(request_data)

headers = {
"tin": data["pin"],
"cmcKey": data["communication_key"],
"bhfId": data["branch_id"],
}

route_path, last_request_date = get_route_path("CodeSearchReq")
request_date = last_request_date.strftime("%Y%m%d%H%M%S")

if route_path:
url = f"{data['server_url']}{route_path}"
payload = {"lastReqDt": request_date}

try:
response = asyncio.run(make_post_request(url, payload, headers))

if response["resultCd"] == "000":
frappe.msgprint(f"response: {response}")

update_last_request_date(response["resultDt"], route_path)

else:
handle_errors(
response,
route_path,
document_name=data["name"],
doctype=SETTINGS_DOCTYPE_NAME,
)

except aiohttp.client_exceptions.ClientConnectorError as error:
etims_logger.exception(error, exc_info=True)
frappe.throw(
"Connection failed",
error,
title="Connection Error",
)

except asyncio.exceptions.TimeoutError as error:
etims_logger.exception(error, exc_info=True)
frappe.throw("Timeout Encountered", error, title="Timeout Error")


def make_send_user_details_request(
data, headers, route_path, url, payload, integration_request_name
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ frappe.ui.form.on("Navari KRA eTims Settings", {
},
__("eTims Actions")
);

frm.add_custom_button(
__("Perform Stock Movements Search"),
function () {
frappe.call({
method:
"kenya_compliance.kenya_compliance.apis.apis.perform_stock_movement_search",
args: {
request_data: {
name: frm.doc.name,
company: frm.doc.company,
communication_key: frm.doc.communication_key,
server_url: frm.doc.server_url,
branch_id: frm.doc.bhfid,
pin: frm.doc.tin,
},
},
callback: (response) => {},
error: (error) => {
// Error Handling is Defered to the Server
},
});
},
__("eTims Actions")
);
}
},
sandbox: function (frm) {
Expand Down

0 comments on commit 738107c

Please sign in to comment.