diff --git a/kenya_compliance/hooks.py b/kenya_compliance/hooks.py index 5cc8086..5ca92a1 100644 --- a/kenya_compliance/hooks.py +++ b/kenya_compliance/hooks.py @@ -292,7 +292,6 @@ "kenya_compliance.kenya_compliance.background_tasks.tasks.send_stock_information", "kenya_compliance.kenya_compliance.background_tasks.tasks.send_purchase_information", "kenya_compliance.kenya_compliance.background_tasks.tasks.send_item_inventory_information", - "kenya_compliance.kenya_compliance.background_tasks.tasks.refresh_notices", ], # "weekly": [ # "kenya_compliance.tasks.weekly" diff --git a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.js b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.js index 7a79cec..e97b975 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.js +++ b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.js @@ -125,4 +125,17 @@ frappe.ui.form.on('Navari KRA eTims Settings', { frm.set_value('server_url', productionServerUrl); } }, + init_devc: function (frm) { + if(frm.is_new()){ + if(frm.doc.init_devc){ + frm.get_field("communication_key").df.read_only = 0; + frm.get_field("communication_key").df.reqd = 1; + frm.refresh_field("communication_key"); + }else{ + frm.get_field("communication_key").df.read_only = 1; + frm.get_field("communication_key").df.reqd = 0; + frm.refresh_field("communication_key"); + } + } + } }); diff --git a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.json b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.json index a62229e..11afe05 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.json +++ b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.json @@ -1,348 +1,356 @@ { - "actions": [], - "allow_rename": 1, - "autoname": "hash", - "creation": "2024-02-19 01:07:18.311952", - "doctype": "DocType", - "engine": "InnoDB", - "field_order": [ - "environment_section", - "sandbox", - "column_break_swix", - "env", - "is_active", - "autocreate_branch_dimension", - "settings_section", - "server_url", - "company", - "tin", - "column_break_mmvk", - "bhfid", - "dvcsrlno", - "communication_key_section", - "communication_key", - "request_frequency_tab", - "frequency_of_communication_with_etims_servers_section", - "sales_information_submission", - "sales_info_cron_format", - "column_break_ukgx", - "stock_information_submission", - "stock_info_cron_format", - "column_break_ifui", - "purchase_information_submission", - "purchase_info_cron_format", - "column_break_fsjl", - "notices_refresh_frequency", - "notices_refresh_freq_cron_format", - "section_break_zbfm", - "most_recent_sales_number", - "field_defaults_tab", - "sales_details_defaults_section", - "sales_payment_type", - "column_break_qugc", - "sales_transaction_progress", - "purchase_details_defaults_section", - "purchases_payment_type", - "purchases_purchase_type", - "column_break_mxxv", - "purchases_receipt_type", - "purchases_purchase_status" - ], - "fields": [ - { - "fieldname": "settings_section", - "fieldtype": "Section Break", - "label": "Settings Definition" - }, - { - "default": "1", - "description": "Marks current environment as either Sandbox, or Production.", - "fieldname": "sandbox", - "fieldtype": "Check", - "label": "Sandbox Environment", - "no_copy": 1 - }, - { - "default": "https://etims-api-sbx.kra.go.ke/etims-api", - "description": "KRA E-Tims Server URL. Don't fill if you're not sure what to input.", - "fieldname": "server_url", - "fieldtype": "Data", - "label": "Server URL", - "options": "URL", - "reqd": 1 - }, - { - "fetch_from": "company.tax_id", - "fieldname": "tin", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Tax Payer's PIN", - "reqd": 1 - }, - { - "fieldname": "dvcsrlno", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Device Serial Number", - "no_copy": 1, - "reqd": 1 - }, - { - "description": "00 is Head-Office/Headquarters, 01 to 99 is Branch Office", - "fieldname": "bhfid", - "fieldtype": "Link", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Branch Id", - "no_copy": 1, - "options": "Branch", - "reqd": 1 - }, - { - "fieldname": "environment_section", - "fieldtype": "Section Break", - "label": "Environment" - }, - { - "fieldname": "column_break_mmvk", - "fieldtype": "Column Break" - }, - { - "default": "Sandbox", - "fieldname": "env", - "fieldtype": "Select", - "in_list_view": 1, - "label": "Environment", - "options": "\nSandbox\nProduction", - "read_only": 1 - }, - { - "fieldname": "column_break_swix", - "fieldtype": "Column Break" - }, - { - "fieldname": "company", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Company", - "options": "Company", - "reqd": 1 - }, - { - "default": "0", - "fieldname": "is_active", - "fieldtype": "Check", - "in_list_view": 1, - "label": "Is Active", - "options": "1" - }, - { - "fieldname": "communication_key_section", - "fieldtype": "Section Break", - "label": "Communication Key" - }, - { - "fieldname": "communication_key", - "fieldtype": "Data", - "label": "Communication Key", - "no_copy": 1, - "read_only": 1 - }, - { - "fieldname": "request_frequency_tab", - "fieldtype": "Tab Break", - "label": "Submission Frequency Settings" - }, - { - "fieldname": "frequency_of_communication_with_etims_servers_section", - "fieldtype": "Section Break", - "label": "Frequency of Communication with eTims Servers" - }, - { - "default": "All", - "fieldname": "sales_information_submission", - "fieldtype": "Select", - "label": "Sales Information Submission Frequency", - "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" - }, - { - "fieldname": "column_break_ukgx", - "fieldtype": "Column Break" - }, - { - "default": "All", - "fieldname": "stock_information_submission", - "fieldtype": "Select", - "label": "Stock Information Submission Frequency", - "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" - }, - { - "fieldname": "column_break_ifui", - "fieldtype": "Column Break" - }, - { - "default": "All", - "fieldname": "purchase_information_submission", - "fieldtype": "Select", - "label": "Purchase Information Submission Frequency", - "mandatory_depends_on": "eval:doc.purchase_information_submission === \"Cron Format\";", - "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" - }, - { - "fieldname": "section_break_zbfm", - "fieldtype": "Section Break" - }, - { - "default": "0", - "fieldname": "most_recent_sales_number", - "fieldtype": "Int", - "label": "Most Recent Sales Number", - "non_negative": 1, - "print_hide": 1, - "read_only": 1 - }, - { - "depends_on": "eval:doc.sales_information_submission === \"Cron\";", - "fieldname": "sales_info_cron_format", - "fieldtype": "Data", - "label": "Sales Info. Cron Format", - "mandatory_depends_on": "eval:doc.sales_information_submission === \"Cron\";" - }, - { - "depends_on": "eval:doc.stock_information_submission === \"Cron\";", - "fieldname": "stock_info_cron_format", - "fieldtype": "Data", - "label": "Stock Info. Cron Format", - "mandatory_depends_on": "eval:doc.stock_information_submission === \"Cron\";" - }, - { - "depends_on": "eval:doc.purchase_information_submission === \"Cron\";", - "fieldname": "purchase_info_cron_format", - "fieldtype": "Data", - "label": "Purchase Info. Cron Format", - "mandatory_depends_on": "eval:doc.purchase_information_submission === \"Cron\";" - }, - { - "default": "1", - "description": "Auto creates the \"Branch\" Accounting Dimension which will be mandatory for all P&L transactions. Recommended.", - "fieldname": "autocreate_branch_dimension", - "fieldtype": "Check", - "label": "Auto Create Branch Accounting Dimension" - }, - { - "fieldname": "field_defaults_tab", - "fieldtype": "Tab Break", - "label": "Field Defaults" - }, - { - "fieldname": "sales_details_defaults_section", - "fieldtype": "Section Break", - "label": "Sales Details Defaults" - }, - { - "fieldname": "column_break_qugc", - "fieldtype": "Column Break" - }, - { - "default": "CASH", - "fieldname": "sales_payment_type", - "fieldtype": "Link", - "label": "Payment Type", - "options": "Navari KRA eTims Payment Type" - }, - { - "default": "Approved", - "fieldname": "sales_transaction_progress", - "fieldtype": "Link", - "label": "Transaction Progress", - "options": "Navari KRA eTims Transaction Progress" - }, - { - "fieldname": "purchase_details_defaults_section", - "fieldtype": "Section Break", - "label": "Purchase Details Defaults" - }, - { - "fieldname": "column_break_mxxv", - "fieldtype": "Column Break" - }, - { - "default": "Normal", - "fieldname": "purchases_purchase_type", - "fieldtype": "Link", - "label": "Purchase Type", - "options": "Navari eTims Transaction Type" - }, - { - "default": "Purchase", - "fieldname": "purchases_receipt_type", - "fieldtype": "Link", - "label": "Receipt Type", - "options": "Navari eTims Purchase Receipt Type" - }, - { - "default": "CASH", - "fieldname": "purchases_payment_type", - "fieldtype": "Link", - "label": "Payment Type", - "options": "Navari KRA eTims Payment Type" - }, - { - "default": "Approved", - "fieldname": "purchases_purchase_status", - "fieldtype": "Link", - "label": "Purchase Status", - "options": "Navari KRA eTims Transaction Progress" - }, - { - "fieldname": "column_break_fsjl", - "fieldtype": "Column Break" - }, - { - "default": "Hourly", - "fieldname": "notices_refresh_frequency", - "fieldtype": "Select", - "label": "Notices Refresh Frequency", - "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" - }, - { - "depends_on": "eval:doc.notices_refresh_frequency === \"Cron\";", - "fieldname": "notices_refresh_freq_cron_format", - "fieldtype": "Data", - "label": "Notices Refresh Freq. Cron Format", - "mandatory_depends_on": "eval:doc.notices_refresh_frequency === \"Cron\";" - } - ], - "index_web_pages_for_search": 1, - "links": [ - { - "group": "Linked Requests", - "link_doctype": "Integration Request", - "link_fieldname": "reference_docname" - } - ], - "modified": "2024-06-28 11:33:09.942158", - "modified_by": "Administrator", - "module": "Kenya Compliance", - "name": "Navari KRA eTims Settings", - "naming_rule": "Random", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], - "sort_field": "modified", - "sort_order": "DESC", - "states": [], - "track_changes": 1 -} + "actions": [], + "allow_rename": 1, + "autoname": "hash", + "creation": "2024-02-19 01:07:18.311952", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "environment_section", + "sandbox", + "column_break_swix", + "env", + "is_active", + "autocreate_branch_dimension", + "settings_section", + "server_url", + "company", + "tin", + "column_break_mmvk", + "bhfid", + "dvcsrlno", + "init_devc", + "communication_key_section", + "communication_key", + "request_frequency_tab", + "frequency_of_communication_with_etims_servers_section", + "sales_information_submission", + "sales_info_cron_format", + "column_break_ukgx", + "stock_information_submission", + "stock_info_cron_format", + "column_break_ifui", + "purchase_information_submission", + "column_break_fsjl", + "notices_refresh_frequency", + "notices_refresh_freq_cron_format", + "purchase_info_cron_format", + "section_break_zbfm", + "most_recent_sales_number", + "field_defaults_tab", + "sales_details_defaults_section", + "sales_payment_type", + "column_break_qugc", + "sales_transaction_progress", + "purchase_details_defaults_section", + "purchases_payment_type", + "purchases_purchase_type", + "column_break_mxxv", + "purchases_receipt_type", + "purchases_purchase_status" + ], + "fields": [ + { + "fieldname": "settings_section", + "fieldtype": "Section Break", + "label": "Settings Definition" + }, + { + "default": "1", + "description": "Marks current environment as either Sandbox, or Production.", + "fieldname": "sandbox", + "fieldtype": "Check", + "label": "Sandbox Environment", + "no_copy": 1 + }, + { + "default": "https://etims-api-sbx.kra.go.ke/etims-api", + "description": "KRA E-Tims Server URL. Don't fill if you're not sure what to input.", + "fieldname": "server_url", + "fieldtype": "Data", + "label": "Server URL", + "options": "URL", + "reqd": 1 + }, + { + "fetch_from": "company.tax_id", + "fieldname": "tin", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Tax Payer's PIN", + "reqd": 1 + }, + { + "fieldname": "dvcsrlno", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Device Serial Number", + "no_copy": 1, + "reqd": 1 + }, + { + "description": "00 is Head-Office/Headquarters, 01 to 99 is Branch Office", + "fieldname": "bhfid", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Branch Id", + "no_copy": 1, + "options": "Branch", + "reqd": 1 + }, + { + "fieldname": "environment_section", + "fieldtype": "Section Break", + "label": "Environment" + }, + { + "fieldname": "column_break_mmvk", + "fieldtype": "Column Break" + }, + { + "default": "Sandbox", + "fieldname": "env", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Environment", + "options": "\nSandbox\nProduction", + "read_only": 1 + }, + { + "fieldname": "column_break_swix", + "fieldtype": "Column Break" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "default": "0", + "fieldname": "is_active", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Is Active", + "options": "1" + }, + { + "fieldname": "communication_key_section", + "fieldtype": "Section Break", + "label": "Communication Key" + }, + { + "fieldname": "communication_key", + "fieldtype": "Data", + "label": "Communication Key", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "request_frequency_tab", + "fieldtype": "Tab Break", + "label": "Submission Frequency Settings" + }, + { + "fieldname": "frequency_of_communication_with_etims_servers_section", + "fieldtype": "Section Break", + "label": "Frequency of Communication with eTims Servers" + }, + { + "default": "All", + "fieldname": "sales_information_submission", + "fieldtype": "Select", + "label": "Sales Information Submission Frequency", + "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" + }, + { + "fieldname": "column_break_ukgx", + "fieldtype": "Column Break" + }, + { + "default": "All", + "fieldname": "stock_information_submission", + "fieldtype": "Select", + "label": "Stock Information Submission Frequency", + "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" + }, + { + "fieldname": "column_break_ifui", + "fieldtype": "Column Break" + }, + { + "default": "All", + "fieldname": "purchase_information_submission", + "fieldtype": "Select", + "label": "Purchase Information Submission Frequency", + "mandatory_depends_on": "eval:doc.purchase_information_submission === \"Cron Format\";", + "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" + }, + { + "fieldname": "section_break_zbfm", + "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "most_recent_sales_number", + "fieldtype": "Int", + "label": "Most Recent Sales Number", + "non_negative": 1, + "print_hide": 1, + "read_only": 1 + }, + { + "depends_on": "eval:doc.sales_information_submission === \"Cron\";", + "fieldname": "sales_info_cron_format", + "fieldtype": "Data", + "label": "Sales Info. Cron Format", + "mandatory_depends_on": "eval:doc.sales_information_submission === \"Cron\";" + }, + { + "depends_on": "eval:doc.stock_information_submission === \"Cron\";", + "fieldname": "stock_info_cron_format", + "fieldtype": "Data", + "label": "Stock Info. Cron Format", + "mandatory_depends_on": "eval:doc.stock_information_submission === \"Cron\";" + }, + { + "depends_on": "eval:doc.purchase_information_submission === \"Cron\";", + "fieldname": "purchase_info_cron_format", + "fieldtype": "Data", + "label": "Purchase Info. Cron Format", + "mandatory_depends_on": "eval:doc.purchase_information_submission === \"Cron\";" + }, + { + "default": "1", + "description": "Auto creates the \"Branch\" Accounting Dimension which will be mandatory for all P&L transactions. Recommended.", + "fieldname": "autocreate_branch_dimension", + "fieldtype": "Check", + "label": "Auto Create Branch Accounting Dimension" + }, + { + "fieldname": "field_defaults_tab", + "fieldtype": "Tab Break", + "label": "Field Defaults" + }, + { + "fieldname": "sales_details_defaults_section", + "fieldtype": "Section Break", + "label": "Sales Details Defaults" + }, + { + "fieldname": "column_break_qugc", + "fieldtype": "Column Break" + }, + { + "default": "CASH", + "fieldname": "sales_payment_type", + "fieldtype": "Link", + "label": "Payment Type", + "options": "Navari KRA eTims Payment Type" + }, + { + "default": "Approved", + "fieldname": "sales_transaction_progress", + "fieldtype": "Link", + "label": "Transaction Progress", + "options": "Navari KRA eTims Transaction Progress" + }, + { + "fieldname": "purchase_details_defaults_section", + "fieldtype": "Section Break", + "label": "Purchase Details Defaults" + }, + { + "fieldname": "column_break_mxxv", + "fieldtype": "Column Break" + }, + { + "default": "Normal", + "fieldname": "purchases_purchase_type", + "fieldtype": "Link", + "label": "Purchase Type", + "options": "Navari eTims Transaction Type" + }, + { + "default": "Purchase", + "fieldname": "purchases_receipt_type", + "fieldtype": "Link", + "label": "Receipt Type", + "options": "Navari eTims Purchase Receipt Type" + }, + { + "default": "CASH", + "fieldname": "purchases_payment_type", + "fieldtype": "Link", + "label": "Payment Type", + "options": "Navari KRA eTims Payment Type" + }, + { + "default": "Approved", + "fieldname": "purchases_purchase_status", + "fieldtype": "Link", + "label": "Purchase Status", + "options": "Navari KRA eTims Transaction Progress" + }, + { + "default": "0", + "description": "If the device has already been initialized and you have your Communication Key", + "fieldname": "init_devc", + "fieldtype": "Check", + "label": "Initialized Device" + }, + { + "fieldname": "column_break_fsjl", + "fieldtype": "Column Break" + }, + { + "default": "Hourly", + "fieldname": "notices_refresh_frequency", + "fieldtype": "Select", + "label": "Notices Refresh Frequency", + "options": "\nAll\nHourly\nDaily\nWeekly\nMonthly\nYearly\nAnnual\nCron" + }, + { + "depends_on": "eval:doc.notices_refresh_frequency === \"Cron\";", + "fieldname": "notices_refresh_freq_cron_format", + "fieldtype": "Data", + "label": "Notices Refresh Freq. Cron Format", + "mandatory_depends_on": "eval:doc.notices_refresh_frequency === \"Cron\";" + } + ], + "index_web_pages_for_search": 1, + "links": [ + { + "group": "Linked Requests", + "link_doctype": "Integration Request", + "link_fieldname": "reference_docname" + } + ], + "modified": "2024-06-27 18:05:15.682492", + "modified_by": "Administrator", + "module": "Kenya Compliance", + "name": "Navari KRA eTims Settings", + "naming_rule": "Random", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.py b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.py index 9068d90..ed31a09 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.py +++ b/kenya_compliance/kenya_compliance/doctype/navari_kra_etims_settings/navari_kra_etims_settings.py @@ -16,7 +16,6 @@ send_purchase_information, send_sales_invoices_information, send_stock_information, - refresh_notices, ) from ...handlers import handle_errors from ...logger import etims_logger @@ -225,23 +224,6 @@ def on_update(self) -> None: purchase_information_task.save() - if self.notices_refresh_frequency: - notices_refresh_task_name = refresh_notices.__name__ - - notices_refresh_task = frappe.get_doc( - "Scheduled Job Type", - {"method": ["like", f"%{notices_refresh_task_name}%"]}, - ["name", "method", "frequency"], - for_update=True, - ) - - notices_refresh_task.frequency = self.notices_refresh_frequency - - if self.notices_refresh_frequency == "Cron": - notices_refresh_task.cron_format = self.notices_refresh_freq_cron_format - - notices_refresh_task.save() - def before_insert(self) -> None: """Before Insertion Hook""" route_path, last_request_date = get_route_path("DeviceVerificationReq") @@ -263,7 +245,25 @@ def before_insert(self) -> None: ) try: - response = asyncio.run(make_post_request(url, payload)) + response = None + if self.init_devc: + import datetime + time_stamp = datetime.datetime.now() + response = { + "resultCd": "000", + "resultMsg": "Successful", + "resultDt": time_stamp.strftime("%Y%m%d%H%M%S"), + "data": { + "info": { + "tin": self.tin, + "taxprNm": self.company, + "bhfId": self.bhfid, + "cmcKey": self.communication_key + } + } + } + else: + response = asyncio.run(make_post_request(url, payload)) if response["resultCd"] == "000": self.communication_key = response["data"]["info"]["cmcKey"] diff --git a/kenya_compliance/kenya_compliance/overrides/client/items_list.js b/kenya_compliance/kenya_compliance/overrides/client/items_list.js index 8e61e6b..040c813 100644 --- a/kenya_compliance/kenya_compliance/overrides/client/items_list.js +++ b/kenya_compliance/kenya_compliance/overrides/client/items_list.js @@ -19,7 +19,8 @@ frappe.listview_settings[doctypeName].onload = function (listview) { // Error Handling is Defered to the Server }, }); - } + }, + __("eTIMS Actions") ); listview.page.add_inner_button(__("Get Imported Items"), function (listview) { @@ -36,7 +37,8 @@ frappe.listview_settings[doctypeName].onload = function (listview) { // Error Handling is Defered to the Server }, }); - }); + }, + __("eTIMS Actions")); listview.page.add_inner_button( __("Search Items Classification"), @@ -54,7 +56,8 @@ frappe.listview_settings[doctypeName].onload = function (listview) { // Error Handling is Defered to the Server }, }); - } + }, + __("eTIMS Actions") ); listview.page.add_action_item(__("Bulk Register Items"), function () { @@ -74,5 +77,6 @@ frappe.listview_settings[doctypeName].onload = function (listview) { // Error Handling is Defered to the Server }, }); - }); + }, + __("eTIMS Actions")); };