From 0711d0293d3a57a0f7e73d4d8bce1c46675a0bfa Mon Sep 17 00:00:00 2001 From: maniamartial Date: Fri, 29 Nov 2024 09:46:13 +0300 Subject: [PATCH] feat - let the user enter branch id while fetching Stock count --- ...ri_etims_registered_stock_movement_list.js | 75 ++++++++++++++++--- .../navari_etims_routes.json | 4 +- .../navari_kra_etims_settings.json | 4 +- kenya_compliance/kenya_compliance/utils.py | 7 ++ 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_stock_movement/navari_etims_registered_stock_movement_list.js b/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_stock_movement/navari_etims_registered_stock_movement_list.js index 797f919..6a4db63 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_stock_movement/navari_etims_registered_stock_movement_list.js +++ b/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_stock_movement/navari_etims_registered_stock_movement_list.js @@ -1,3 +1,30 @@ +// const doctypeName = "Navari eTims Registered Stock Movement"; + +// frappe.listview_settings[doctypeName] = { +// onload: function (listview) { +// const companyName = frappe.boot.sysdefaults.company; + +// listview.page.add_inner_button( +// __("Get Stock Movements"), +// function (listview) { +// frappe.call({ +// method: +// "kenya_compliance.kenya_compliance.apis.apis.perform_stock_movement_search", +// args: { +// request_data: { +// company_name: companyName, +// branch_id: "", +// }, +// }, +// callback: (response) => {}, +// error: (error) => { +// // Error Handling is Defered to the Server +// }, +// }); +// }, +// ); +// }, +// }; const doctypeName = "Navari eTims Registered Stock Movement"; frappe.listview_settings[doctypeName] = { @@ -6,21 +33,47 @@ frappe.listview_settings[doctypeName] = { listview.page.add_inner_button( __("Get Stock Movements"), - function (listview) { - frappe.call({ - method: - "kenya_compliance.kenya_compliance.apis.apis.perform_stock_movement_search", - args: { - request_data: { - company_name: companyName, + function () { + // Create a dialog to select a branch + const branchDialog = new frappe.ui.Dialog({ + title: __("Select Branch"), + fields: [ + { + label: __("Branch"), + fieldname: "branch_id", + fieldtype: "Link", + options: "Branch", + reqd: true, }, - }, - callback: (response) => {}, - error: (error) => { - // Error Handling is Defered to the Server + ], + primary_action_label: __("Submit"), + primary_action: function (data) { + branchDialog.hide(); + + // Call the server method with the selected branch + frappe.call({ + method: + "kenya_compliance.kenya_compliance.apis.apis.perform_stock_movement_search", + args: { + request_data: { + company_name: companyName, + branch_id: data.branch_id, + }, + }, + callback: (response) => { + frappe.msgprint(__("Stock movements retrieved successfully.")); + }, + error: (error) => { + frappe.msgprint(__("An error occurred while fetching stock movements.")); + }, + }); }, }); + + // Show the dialog + branchDialog.show(); }, ); }, }; + diff --git a/kenya_compliance/kenya_compliance/doctype/navari_etims_routes/navari_etims_routes.json b/kenya_compliance/kenya_compliance/doctype/navari_etims_routes/navari_etims_routes.json index f86367d..6784042 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_etims_routes/navari_etims_routes.json +++ b/kenya_compliance/kenya_compliance/doctype/navari_etims_routes/navari_etims_routes.json @@ -35,7 +35,7 @@ "fieldname": "vendor", "fieldtype": "Select", "in_list_view": 1, - "label": "Vendor", + "label": "API Provider", "options": "\nOSCU KRA\nVSCU Slade 360\nPergamon", "reqd": 1 }, @@ -53,7 +53,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-11-28 10:27:29.129037", + "modified": "2024-11-29 08:38:06.929415", "modified_by": "Administrator", "module": "Kenya Compliance", "name": "Navari eTims Routes", 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 4969254..74dc927 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 @@ -308,7 +308,7 @@ { "fieldname": "vendor", "fieldtype": "Select", - "label": "Vendor", + "label": "API Provider", "options": "\nOSCU KRA\nVSCU Slade 360\nPergamon", "reqd": 1 } @@ -321,7 +321,7 @@ "link_fieldname": "reference_docname" } ], - "modified": "2024-11-28 10:15:43.219826", + "modified": "2024-11-29 08:37:26.434270", "modified_by": "Administrator", "module": "Kenya Compliance", "name": "Navari KRA eTims Settings", diff --git a/kenya_compliance/kenya_compliance/utils.py b/kenya_compliance/kenya_compliance/utils.py index 24ba3f4..56fc4a4 100644 --- a/kenya_compliance/kenya_compliance/utils.py +++ b/kenya_compliance/kenya_compliance/utils.py @@ -252,6 +252,13 @@ def build_headers(company_name: str, vendor:str, branch_id: str = "00") -> dict[ return headers +def get_branch_id(company_name: str, vendor: str) -> str | None: + settings = get_curr_env_etims_settings(company_name, vendor) + + if settings: + return settings.bhfid + + return None def extract_document_series_number(document: Document) -> int | None: split_invoice_name = document.name.split("-")