Skip to content

Commit

Permalink
fix - search stock movement in all branch(initial fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
maniamartial committed Nov 29, 2024
1 parent 0711d02 commit d4ab6ca
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 240 deletions.
14 changes: 12 additions & 2 deletions kenya_compliance/kenya_compliance/apis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 <b>Navari eTims Registered Imported Item</b> Doctype for more information"
)



def search_branch_request_on_success(response: dict) -> None:
for branch in response["data"]["bhfList"]:
doc = None
Expand Down
Loading

0 comments on commit d4ab6ca

Please sign in to comment.