-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored the document overrides into overrides folder containing cl…
…ient and server overrides. Implemented client and server functionality for Sales Invoice. Added mandatory dependencies to hooks.py. Made communication key non-mandatory in communication key doctype. Refactored function for clean project structure.
- Loading branch information
1 parent
60558ca
commit 024ce84
Showing
9 changed files
with
191 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
*.swp | ||
tags | ||
|
||
/.vscode | ||
**/.vscode | ||
/.idea | ||
/node_modules | ||
/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
kenya_compliance/kenya_compliance/overrides/client/sales_invoice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const doctype = "Sales Invoice"; | ||
const childDoctype = "Sales Invoice Item"; | ||
|
||
frappe.ui.form.on(doctype, { | ||
refresh: function (frm) { | ||
frm.fields_dict.items.grid.get_field("item_classification_code").get_query = | ||
function (doc, cdt, cdn) { | ||
const itemDescription = locals[cdt][cdn].description; | ||
const descriptionText = parseItemDescriptText(itemDescription); | ||
|
||
return { | ||
filters: [ | ||
[ | ||
"Navari KRA eTims Item Classification", | ||
"itemclsnm", | ||
"like", | ||
`%${descriptionText}%`, | ||
], | ||
], | ||
}; | ||
}; | ||
}, | ||
}); | ||
|
||
frappe.ui.form.on(childDoctype, { | ||
item_classification_code: async function (frm, cdt, cdn) { | ||
const itemClassificationCode = locals[cdt][cdn].item_classification_code; | ||
|
||
if (itemClassificationCode) { | ||
const response = await frappe.db.get_value( | ||
"Navari KRA eTims Item Classification", | ||
{ itemclscd: itemClassificationCode }, | ||
["*"] | ||
); | ||
|
||
frappe.model.set_value( | ||
cdt, | ||
cdn, | ||
"taxation_type", | ||
response.message?.taxtycd | ||
); | ||
} | ||
}, | ||
}); | ||
|
||
function parseItemDescriptText(description) { | ||
const temp = document.createElement("div"); | ||
|
||
temp.innerHTML = description; | ||
const descriptionText = temp.textContent || temp.innerText; | ||
|
||
return descriptionText; | ||
} |
62 changes: 62 additions & 0 deletions
62
kenya_compliance/kenya_compliance/overrides/server/sales_invoice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import asyncio | ||
|
||
import aiohttp | ||
import frappe | ||
from frappe.model.document import Document | ||
|
||
from ...logger import etims_logger | ||
from ...utils import ( | ||
build_headers, | ||
get_last_request_date, | ||
get_route_path, | ||
get_server_url, | ||
make_post_request, | ||
queue_request, | ||
) | ||
|
||
|
||
def on_submit(doc: Document, method: str) -> None: | ||
"""Intercepts submit event for document""" | ||
error_messages = None | ||
headers = build_headers(doc) | ||
last_request_date = get_last_request_date() | ||
|
||
if headers and last_request_date: | ||
server_url = get_server_url(doc) | ||
route_path = get_route_path("CodeSearchReq") | ||
|
||
if server_url and route_path: | ||
url = f"{server_url}{route_path}" | ||
|
||
try: | ||
# TODO: Run job in background | ||
response = asyncio.run( | ||
make_post_request(url, {"lastReqDt": "20230101000000"}, headers) | ||
) | ||
|
||
if response: | ||
print(f"{response}") | ||
raise Exception | ||
except aiohttp.client_exceptions.ClientConnectorError as error: | ||
etims_logger.exception(error, exc_info=True) | ||
frappe.throw( | ||
"Connection failed", | ||
error, | ||
title="Connection Error", | ||
) | ||
|
||
elif not headers: | ||
error_messages = ( | ||
"Headers not set for %s. Please ensure the tax Id is properly set" | ||
% doc.name | ||
) | ||
etims_logger.error(error_messages) | ||
frappe.throw(error_messages, title="Incorrect Setup") | ||
|
||
elif not last_request_date: | ||
error_messages = ( | ||
"Last Request Date is not set for %s. Please ensure it is properly set" | ||
% doc.name | ||
) | ||
etims_logger.error(error_messages) | ||
frappe.throw(error_messages, title="Incorrect Setup") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters