|
|
|
@ -41,7 +41,7 @@ def create_or_update_address(address: dict, address_type: str, customer: str) ->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
address_doc.update({
|
|
|
|
address_doc.update({
|
|
|
|
"title": address.get("AddressName"),
|
|
|
|
"address_title": address.get("AddressName"),
|
|
|
|
"address_line1": address.get("Address1"),
|
|
|
|
"address_line1": address.get("Address1"),
|
|
|
|
"address_line2": address.get("Address2"),
|
|
|
|
"address_line2": address.get("Address2"),
|
|
|
|
"city": address.get("City"),
|
|
|
|
"city": address.get("City"),
|
|
|
|
@ -75,26 +75,6 @@ def get_sps_item_code_if_exists(order_uom: str, description: str, sku: str, sett
|
|
|
|
if frappe.db.exists("Item", {"item_code": sku}):
|
|
|
|
if frappe.db.exists("Item", {"item_code": sku}):
|
|
|
|
return sku
|
|
|
|
return sku
|
|
|
|
|
|
|
|
|
|
|
|
# item_doc = frappe.new_doc("Item")
|
|
|
|
|
|
|
|
# item_doc.update({
|
|
|
|
|
|
|
|
# "item_code": sku,
|
|
|
|
|
|
|
|
# "item_name": description,
|
|
|
|
|
|
|
|
# "stock_uom": get_uom(order_uom) if order_uom != "EA" and order_uom != None else frappe.get_value("SPS Integration Settings", setting_doc, "default_uom"),
|
|
|
|
|
|
|
|
# "item_group": frappe.get_value("SPS Integration Settings", setting_doc, "default_item_group"),
|
|
|
|
|
|
|
|
# "custom_item_shipping_category": frappe.get_value("SPS Integration Settings", setting_doc, "shipping_category")
|
|
|
|
|
|
|
|
# })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# try:
|
|
|
|
|
|
|
|
# item_doc.save()
|
|
|
|
|
|
|
|
# frappe.db.commit()
|
|
|
|
|
|
|
|
# except:
|
|
|
|
|
|
|
|
# frappe.log_error(
|
|
|
|
|
|
|
|
# title="Item creation",
|
|
|
|
|
|
|
|
# message=f"{frappe.get_traceback()}"
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# return item_doc.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_uom(uom: str) -> str:
|
|
|
|
def get_uom(uom: str) -> str:
|
|
|
|
"""Get or create UOM."""
|
|
|
|
"""Get or create UOM."""
|
|
|
|
if frappe.db.exists("UOM", uom):
|
|
|
|
if frappe.db.exists("UOM", uom):
|
|
|
|
@ -156,66 +136,6 @@ def get_link_row(docname: str, link_name: str) -> Dict:
|
|
|
|
row["link_name"] = link_name
|
|
|
|
row["link_name"] = link_name
|
|
|
|
return row
|
|
|
|
return row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def check_and_create_contact(data, setting_doc):
|
|
|
|
|
|
|
|
# """Check if contacts exist, else create new contacts"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# addresses = data.get('Header', {}).get('Address', [])
|
|
|
|
|
|
|
|
# contacts = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# for address in addresses:
|
|
|
|
|
|
|
|
# if address.get("AddressTypeCode") == "BT" and address.get("Contacts"):
|
|
|
|
|
|
|
|
# contacts = address["Contacts"]
|
|
|
|
|
|
|
|
# break # Stop once billing contacts are found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if not contacts:
|
|
|
|
|
|
|
|
# for address in addresses:
|
|
|
|
|
|
|
|
# if address.get("AddressTypeCode") == "ST" and address.get("Contacts"):
|
|
|
|
|
|
|
|
# contacts = address["Contacts"]
|
|
|
|
|
|
|
|
# break # Stop once shipping contacts are found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if not contacts:
|
|
|
|
|
|
|
|
# return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Check if customer exists
|
|
|
|
|
|
|
|
# customer_exists, customer_name = check_customer_if_exists(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if customer_exists:
|
|
|
|
|
|
|
|
# # Check if the contact email already exists
|
|
|
|
|
|
|
|
# email_id = contacts[0].get("PrimaryEmail", "")
|
|
|
|
|
|
|
|
# if frappe.db.exists("Contact Email", {"email_id": email_id}):
|
|
|
|
|
|
|
|
# contact_name = frappe.get_value(
|
|
|
|
|
|
|
|
# "Contact Email", {"email_id": email_id}, "parent"
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# doc = frappe.new_doc("Contact")
|
|
|
|
|
|
|
|
# doc.first_name = customer_name
|
|
|
|
|
|
|
|
# if email_id:
|
|
|
|
|
|
|
|
# email_row = {
|
|
|
|
|
|
|
|
# "email_id": email_id,
|
|
|
|
|
|
|
|
# "is_primary": 1
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# doc.append("email_ids", email_row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# phone_number = contacts[0].get("PrimaryPhone", "")
|
|
|
|
|
|
|
|
# if phone_number:
|
|
|
|
|
|
|
|
# num_row = {
|
|
|
|
|
|
|
|
# "phone": phone_number,
|
|
|
|
|
|
|
|
# "is_primary_phone": 1
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# doc.append("phone_nos", num_row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# link_row = get_link_row("Customer", customer_name)
|
|
|
|
|
|
|
|
# doc.append("links", link_row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# doc.save()
|
|
|
|
|
|
|
|
# frappe.db.commit()
|
|
|
|
|
|
|
|
# contact_name = doc.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# return contact_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Made the fixes related to assignment error of contact_name variable
|
|
|
|
|
|
|
|
def check_and_create_contact(data, setting_doc):
|
|
|
|
def check_and_create_contact(data, setting_doc):
|
|
|
|
"""Check if contacts exist, else create new contacts"""
|
|
|
|
"""Check if contacts exist, else create new contacts"""
|
|
|
|
|
|
|
|
|
|
|
|
|