Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix26 #16

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading