From d4ab6ca0884d13de687d4e38f6fa9d28cd84aa37 Mon Sep 17 00:00:00 2001 From: maniamartial Date: Fri, 29 Nov 2024 12:26:03 +0300 Subject: [PATCH] fix - search stock movement in all branch(initial fix) --- .../kenya_compliance/apis/apis.py | 14 +- .../apis/remote_response_status_handlers.py | 13 +- ...navari_etims_registered_imported_item.json | 349 +++++++++--------- ...ri_etims_registered_stock_movement_list.js | 124 +++---- 4 files changed, 260 insertions(+), 240 deletions(-) diff --git a/kenya_compliance/kenya_compliance/apis/apis.py b/kenya_compliance/kenya_compliance/apis/apis.py index 49f0886..0c8fcf2 100644 --- a/kenya_compliance/kenya_compliance/apis/apis.py +++ b/kenya_compliance/kenya_compliance/apis/apis.py @@ -612,7 +612,6 @@ def perform_stock_movement_search(request_data: str, vendor="OSCU KRA") -> None: if headers and server_url and route_path: url = f"{server_url}{route_path}" payload = {"lastReqDt": request_date} - endpoints_builder.headers = headers endpoints_builder.url = url endpoints_builder.payload = payload @@ -627,6 +626,18 @@ def perform_stock_movement_search(request_data: str, vendor="OSCU KRA") -> None: job_name=token_hex(100), ) +@frappe.whitelist() +def perform_stock_movement_search_all_branches() -> None: + all_credentials = frappe.get_all( + SETTINGS_DOCTYPE_NAME, + ["name", "bhfid", "communication_key", "tin", "company"], + ) + + for credential in all_credentials: + request_data = json.dumps( + {"company_name": credential.company, "branch_id": credential.bhfid} + ) + perform_stock_movement_search(request_data) @frappe.whitelist() def submit_item_composition(request_data: str, vendor="OSCU KRA") -> None: @@ -727,7 +738,6 @@ def create_supplier(supplier_details: dict) -> Document: @frappe.whitelist() def create_items_from_fetched_registered_purchases(request_data: str) -> None: data = json.loads(request_data) - if data["items"]: items = data["items"] for item in items: diff --git a/kenya_compliance/kenya_compliance/apis/remote_response_status_handlers.py b/kenya_compliance/kenya_compliance/apis/remote_response_status_handlers.py index 74416e9..953c4b2 100644 --- a/kenya_compliance/kenya_compliance/apis/remote_response_status_handlers.py +++ b/kenya_compliance/kenya_compliance/apis/remote_response_status_handlers.py @@ -120,7 +120,6 @@ def submit_inventory_on_success(response: dict, document_name: str) -> None: {"custom_inventory_submitted_successfully": 1}, ) - def sales_information_submission_on_success( response: dict, invoice_type: str, @@ -370,7 +369,13 @@ def create_if_not_exists(doctype: str, code: str) -> str: for item in items: doc = frappe.new_doc(REGISTERED_IMPORTED_ITEM_DOCTYPE_NAME) - + if frappe.db.exists( + REGISTERED_IMPORTED_ITEM_DOCTYPE_NAME, + { + "task_code": item["taskCd"], + }, + ): + continue doc.item_name = item["itemNm"] doc.task_code = item["taskCd"] doc.declaration_date = datetime.strptime(item["dclDe"], "%d%m%Y") @@ -398,14 +403,14 @@ def create_if_not_exists(doctype: str, code: str) -> str: doc.invoice_foreign_currency_amount = item["invcFcurAmt"] doc.invoice_foreign_currency = item["invcFcurCd"] doc.invoice_foreign_currency_rate = item["invcFcurExcrt"] + doc.rate = item["invcFcurAmt"] / item["qty"] doc.save() frappe.msgprint( "Imported Items Fetched. Go to Navari eTims Registered Imported Item Doctype for more information" ) - - + def search_branch_request_on_success(response: dict) -> None: for branch in response["data"]["bhfList"]: doc = None diff --git a/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_imported_item/navari_etims_registered_imported_item.json b/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_imported_item/navari_etims_registered_imported_item.json index ffd1573..166ad8b 100644 --- a/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_imported_item/navari_etims_registered_imported_item.json +++ b/kenya_compliance/kenya_compliance/doctype/navari_etims_registered_imported_item/navari_etims_registered_imported_item.json @@ -1,172 +1,179 @@ { - "actions": [], - "allow_rename": 1, - "autoname": "field:task_code", - "creation": "2024-05-06 10:19:33.747064", - "doctype": "DocType", - "engine": "InnoDB", - "field_order": [ - "item_name", - "origin_nation_code", - "declaration_date", - "item_sequence", - "gross_weight", - "package", - "quantity", - "suppliers_name", - "invoice_foreign_currency_amount", - "column_break_cbnh", - "task_code", - "export_nation_code", - "declaration_number", - "hs_code", - "net_weight", - "packaging_unit_code", - "quantity_unit_code", - "agent_name", - "invoice_foreign_currency", - "invoice_foreign_currency_rate" - ], - "fields": [ - { - "fieldname": "item_name", - "fieldtype": "Data", - "label": "Item Name" - }, - { - "fieldname": "task_code", - "fieldtype": "Data", - "label": "Task Code", - "unique": 1 - }, - { - "fieldname": "declaration_date", - "fieldtype": "Date", - "label": "Declaration Date" - }, - { - "fieldname": "item_sequence", - "fieldtype": "Int", - "label": "Item Sequence" - }, - { - "fieldname": "declaration_number", - "fieldtype": "Data", - "label": "Declaration Number" - }, - { - "fieldname": "hs_code", - "fieldtype": "Data", - "label": "HS Code" - }, - { - "fieldname": "column_break_cbnh", - "fieldtype": "Column Break" - }, - { - "fieldname": "origin_nation_code", - "fieldtype": "Link", - "label": "Origin Nation Code", - "options": "Navari eTims Country" - }, - { - "fieldname": "export_nation_code", - "fieldtype": "Link", - "label": "Export Nation Code", - "options": "Navari eTims Country" - }, - { - "fieldname": "package", - "fieldtype": "Data", - "label": "Package" - }, - { - "fieldname": "packaging_unit_code", - "fieldtype": "Link", - "label": "Packaging Unit Code", - "options": "Navari eTims Packaging Unit" - }, - { - "fieldname": "quantity", - "fieldtype": "Int", - "label": "Quantity" - }, - { - "fieldname": "quantity_unit_code", - "fieldtype": "Link", - "label": "Quantity Unit Code", - "options": "Navari eTims Unit of Quantity" - }, - { - "fieldname": "gross_weight", - "fieldtype": "Float", - "label": "Gross Weight", - "precision": "2" - }, - { - "fieldname": "net_weight", - "fieldtype": "Float", - "label": "Net Weight" - }, - { - "fieldname": "suppliers_name", - "fieldtype": "Data", - "label": "Supplier's Name" - }, - { - "fieldname": "agent_name", - "fieldtype": "Data", - "label": "Agent Name" - }, - { - "fieldname": "invoice_foreign_currency_amount", - "fieldtype": "Data", - "label": "Invoice Foreign Currency Amount" - }, - { - "fieldname": "invoice_foreign_currency", - "fieldtype": "Data", - "label": "Invoice Foreign Currency" - }, - { - "fieldname": "invoice_foreign_currency_rate", - "fieldtype": "Data", - "label": "Invoice Foreign Currency Rate" - } - ], - "in_create": 1, - "index_web_pages_for_search": 1, - "links": [ - { - "link_doctype": "Purchase Invoice", - "link_fieldname": "custom_source_registered_imported_item" - } - ], - "modified": "2024-08-30 15:47:26.632485", - "modified_by": "Administrator", - "module": "Kenya Compliance", - "name": "Navari eTims Registered Imported Item", - "naming_rule": "By fieldname", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], - "search_fields": "item_name, task_code", - "show_title_field_in_link": 1, - "sort_field": "modified", - "sort_order": "DESC", - "states": [], - "title_field": "item_name", - "track_changes": 1 -} + "actions": [], + "allow_rename": 1, + "autoname": "field:task_code", + "creation": "2024-05-06 10:19:33.747064", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "item_name", + "origin_nation_code", + "declaration_date", + "item_sequence", + "gross_weight", + "package", + "quantity", + "suppliers_name", + "invoice_foreign_currency_amount", + "rate", + "column_break_cbnh", + "task_code", + "export_nation_code", + "declaration_number", + "hs_code", + "net_weight", + "packaging_unit_code", + "quantity_unit_code", + "agent_name", + "invoice_foreign_currency", + "invoice_foreign_currency_rate" + ], + "fields": [ + { + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name" + }, + { + "fieldname": "task_code", + "fieldtype": "Data", + "label": "Task Code", + "unique": 1 + }, + { + "fieldname": "declaration_date", + "fieldtype": "Date", + "label": "Declaration Date" + }, + { + "fieldname": "item_sequence", + "fieldtype": "Int", + "label": "Item Sequence" + }, + { + "fieldname": "declaration_number", + "fieldtype": "Data", + "label": "Declaration Number" + }, + { + "fieldname": "hs_code", + "fieldtype": "Data", + "label": "HS Code" + }, + { + "fieldname": "column_break_cbnh", + "fieldtype": "Column Break" + }, + { + "fieldname": "origin_nation_code", + "fieldtype": "Link", + "label": "Origin Nation Code", + "options": "Navari eTims Country" + }, + { + "fieldname": "export_nation_code", + "fieldtype": "Link", + "label": "Export Nation Code", + "options": "Navari eTims Country" + }, + { + "fieldname": "package", + "fieldtype": "Data", + "label": "Package" + }, + { + "fieldname": "packaging_unit_code", + "fieldtype": "Link", + "label": "Packaging Unit Code", + "options": "Navari eTims Packaging Unit" + }, + { + "fieldname": "quantity", + "fieldtype": "Int", + "label": "Quantity" + }, + { + "fieldname": "quantity_unit_code", + "fieldtype": "Link", + "label": "Quantity Unit Code", + "options": "Navari eTims Unit of Quantity" + }, + { + "fieldname": "gross_weight", + "fieldtype": "Float", + "label": "Gross Weight", + "precision": "2" + }, + { + "fieldname": "net_weight", + "fieldtype": "Float", + "label": "Net Weight" + }, + { + "fieldname": "suppliers_name", + "fieldtype": "Data", + "label": "Supplier's Name" + }, + { + "fieldname": "agent_name", + "fieldtype": "Data", + "label": "Agent Name" + }, + { + "fieldname": "invoice_foreign_currency_amount", + "fieldtype": "Data", + "label": "Invoice Foreign Currency Amount" + }, + { + "fieldname": "invoice_foreign_currency", + "fieldtype": "Data", + "label": "Invoice Foreign Currency" + }, + { + "fieldname": "invoice_foreign_currency_rate", + "fieldtype": "Data", + "label": "Invoice Foreign Currency Rate" + }, + { + "fieldname": "rate", + "fieldtype": "Currency", + "label": "Rate", + "options": "invoice_foreign_currency" + } + ], + "in_create": 1, + "index_web_pages_for_search": 1, + "links": [ + { + "link_doctype": "Purchase Invoice", + "link_fieldname": "custom_source_registered_imported_item" + } + ], + "modified": "2024-11-29 10:29:23.412182", + "modified_by": "Administrator", + "module": "Kenya Compliance", + "name": "Navari eTims Registered Imported Item", + "naming_rule": "By fieldname", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "search_fields": "item_name, task_code", + "show_title_field_in_link": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "title_field": "item_name", + "track_changes": 1 +} \ No newline at end of file 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 6a4db63..838cf6b 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,30 +1,3 @@ -// 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] = { @@ -33,47 +6,72 @@ frappe.listview_settings[doctypeName] = { listview.page.add_inner_button( __("Get Stock Movements"), - 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, + function (listview) { + frappe.call({ + method: + "kenya_compliance.kenya_compliance.apis.apis.perform_stock_movement_search_all_branches", + args: { + request_data: { + company_name: companyName, }, - ], - 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.")); - }, - }); + }, + callback: (response) => {}, + error: (error) => { }, }); - - // Show the dialog - branchDialog.show(); }, ); }, }; +// 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 () { +// // 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, +// }, +// ], +// 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(); +// }, +// ); +// }, +// };