Skip to content

Commit

Permalink
Merge pull request #16 from navariltd/fix26
Browse files Browse the repository at this point in the history
Fix26
  • Loading branch information
maniamartial authored Dec 10, 2024
2 parents e5a84cf + eac93f6 commit ae2b990
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def purchase_search_on_success(reponse: dict) -> None:


def create_purchase_from_search_details(fetched_purchase: dict) -> str:
existing_unique_id = check_duplicate_registered_purchase(fetched_purchase)
if existing_unique_id:
return existing_unique_id
doc = frappe.new_doc(REGISTERED_PURCHASES_DOCTYPE_NAME)

doc.supplier_name = fetched_purchase["spplrNm"]
Expand Down Expand Up @@ -234,6 +237,28 @@ def create_purchase_from_search_details(fetched_purchase: dict) -> str:

return doc.name

def check_duplicate_registered_purchase(fetched_purchase: dict) -> str:
"""
Check if a Registered Purchase already exists based on a unique ID.
Args:
fetched_purchase (dict): The purchase details fetched from the source.
Returns:
str: The unique ID if the Registered Purchase exists, else None.
"""

unique_id = f"{fetched_purchase['spplrTin']}-{fetched_purchase['spplrInvcNo']}"

if frappe.db.exists(REGISTERED_PURCHASES_DOCTYPE_NAME, unique_id):
frappe.log_error(
title="Duplicate Registered Purchase",
message=f"Purchase with ID {unique_id} already exists. Skipping creation."
)
return unique_id

return None


def create_and_link_purchase_item(item: dict, parent_record: str) -> None:
item_cls_code = item["itemClsCd"]
Expand Down

0 comments on commit ae2b990

Please sign in to comment.