Skip to content

Commit

Permalink
feat - Validate item mapped if they exist hide button on registered p…
Browse files Browse the repository at this point in the history
…urchases
  • Loading branch information
maniamartial committed Dec 2, 2024
1 parent d4ab6ca commit cadd52f
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 249 deletions.
8 changes: 4 additions & 4 deletions kenya_compliance/kenya_compliance/apis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,21 @@ def perform_import_item_search_all_branches() -> None:
perform_import_item_search(request_data)

@frappe.whitelist()
def perform_purchases_search(request_data: str) -> None:
def perform_purchases_search(request_data: str, vendor: str="OSCU KRA") -> None:
data: dict = json.loads(request_data)

company_name = data["company_name"]

headers = build_headers(company_name)
server_url = get_server_url(company_name)
headers = build_headers(company_name, vendor)
server_url = get_server_url(company_name, vendor)
route_path, last_request_date = get_route_path("TrnsPurchaseSalesReq")

if headers and server_url and route_path:
request_date = last_request_date.strftime("%Y%m%d%H%M%S")

url = f"{server_url}{route_path}"
payload = {"lastReqDt": request_date}

frappe.throw(str(payload))
endpoints_builder.headers = headers
endpoints_builder.url = url
endpoints_builder.payload = payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@
{
"link_doctype": "Purchase Invoice",
"link_fieldname": "custom_source_registered_imported_item"
},
{
"link_doctype": "Item",
"link_fieldname": "custom_referenced_imported_item"
}
],
"modified": "2024-11-29 10:29:23.412182",
"modified": "2024-12-02 08:48:07.182002",
"modified_by": "Administrator",
"module": "Kenya Compliance",
"name": "Navari eTims Registered Imported Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,62 @@ frappe.ui.form.on(doctypeName, {
},
__('eTims Actions'),
);
frm.add_custom_button(
__('Create Items'),
function () {
frappe.call({
method:
'kenya_compliance.kenya_compliance.apis.apis.create_items_from_fetched_registered_purchases',
args: {
request_data: {
name: frm.doc.name,
company_name: companyName,
items: frm.doc.items,
// frm.add_custom_button(
// __('Create Items'),
// function () {
// frappe.call({
// method:
// 'kenya_compliance.kenya_compliance.apis.apis.create_items_from_fetched_registered_purchases',
// args: {
// request_data: {
// name: frm.doc.name,
// company_name: companyName,
// items: frm.doc.items,
// },
// },
// callback: (response) => {},
// error: (error) => {
// // Error Handling is Defered to the Server
// },
// });
// },
// __('eTims Actions'),
// );
// Check for unmapped items before adding the "Create Items" button
frappe.call({
method: 'kenya_compliance.kenya_compliance.doctype.navari_etims_registered_purchases.navari_etims_registered_purchases.validate_item_mapped_and_registered',
args: {
items: frm.doc.items,
},
callback: (response) => {
if (response.message === false) {
frm.add_custom_button(
__('Create Items'),
function () {
frappe.call({
method:
'kenya_compliance.kenya_compliance.apis.apis.create_items_from_fetched_registered_purchases',
args: {
request_data: {
name: frm.doc.name,
company_name: companyName,
items: frm.doc.items,
},
},
},
callback: (response) => {},
error: (error) => {
// Error Handling is Defered to the Server
},
});
},
__('eTims Actions'),
);
callback: (response) => {},
error: (error) => {
},
});
},
__('eTims Actions'),
);
}
},
error: (error) => {
frappe.msgprint(__('Failed to validate items.'));
},
});

frm.add_custom_button(
__('Create Purchase Invoice'),
function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
# Copyright (c) 2024, Navari Ltd and contributors
# For license information, please see license.txt

# import frappe
import frappe
from frappe.model.document import Document


class NavarieTimsRegisteredPurchases(Document):
pass
import json
import frappe

@frappe.whitelist()
def validate_item_mapped_and_registered(items):
'''I dont think this method will work
Reason: We have item with same item name which is used as item code during creation of item,
but they have different item classification'''
try:
items = json.loads(items)

for item in items:
similar_items = frappe.get_all(
"Item",
filters={
"item_name": item.get("item_name"),
"item_code": item.get("item_name"),
# "custom_item_classification": item.get("item_classification_code"),
#"custom_item_code_etims":item.get("item_code"),
"custom_taxation_type": item.get("taxation_type_code"),
},
fields=["name", "item_name", "item_code"],
)
if not similar_items:
frappe.response["message"] = False
return

frappe.response["message"] = True
except Exception as e:
frappe.log_error(f"Error validating items: {str(e)}")

Loading

0 comments on commit cadd52f

Please sign in to comment.