client creation bug fixes
This commit is contained in:
parent
cb33d0c3b3
commit
2ea20a86e3
7 changed files with 52 additions and 19 deletions
|
|
@ -299,7 +299,6 @@ def upsert_client(data):
|
|||
"link_name": customer_doc.name
|
||||
}
|
||||
address_doc.append("links", link)
|
||||
address_doc.save(ignore_permissions=True)
|
||||
contact_exists = frappe.db.exists("Contact", {"email_id": data.get("contact_email")})
|
||||
if not contact_exists:
|
||||
contact_doc = frappe.get_doc({
|
||||
|
|
@ -318,7 +317,8 @@ def upsert_client(data):
|
|||
else:
|
||||
contact_doc = frappe.get_doc("Contact", {"email_id": data.get("contact_email")})
|
||||
print("Contact already exists:", contact_doc.as_dict())
|
||||
|
||||
address_doc.custom_contact = contact_doc.name
|
||||
address_doc.save(ignore_permissions=True)
|
||||
return build_success_response({
|
||||
"customer": customer_doc.as_dict(),
|
||||
"address": address_doc.as_dict(),
|
||||
|
|
|
|||
|
|
@ -126,4 +126,20 @@ def build_success_response(data):
|
|||
"status": "success",
|
||||
"data": data
|
||||
}
|
||||
|
||||
def build_full_address(doc):
|
||||
first_parts = [
|
||||
doc.address_line1,
|
||||
doc.address_line2,
|
||||
doc.city
|
||||
]
|
||||
second_parts = [
|
||||
doc.state,
|
||||
doc.pincode
|
||||
]
|
||||
first = " ".join([p for p in first_parts if p])
|
||||
second = " ".join([p for p in second_parts if p])
|
||||
if first and second:
|
||||
return f"{first}, {second}"
|
||||
return first or second or ""
|
||||
|
||||
9
custom_ui/events/address.py
Normal file
9
custom_ui/events/address.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import frappe
|
||||
from custom_ui.db_utils import build_full_address
|
||||
|
||||
def after_insert(doc, method):
|
||||
print(doc.as_dict())
|
||||
if not doc.full_address:
|
||||
doc.full_address = build_full_address(doc)
|
||||
doc.save()
|
||||
|
||||
|
|
@ -161,7 +161,10 @@ add_to_apps_screen = [
|
|||
doc_events = {
|
||||
"On-Site Meeting": {
|
||||
"after_insert": "custom_ui.events.onsite_meeting.after_insert"
|
||||
}
|
||||
},
|
||||
"Address": {
|
||||
"after_insert": "custom_ui.events.address.after_insert"
|
||||
},
|
||||
}
|
||||
|
||||
# Scheduled Tasks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue