Skip to content

Commit

Permalink
fix(customer): contact creation for companies (#38055)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao authored Nov 12, 2023
1 parent ecc305d commit 9fde782
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions erpnext/selling/doctype/customer/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,14 @@ def set_loyalty_program(self):

def create_contact(contact, party_type, party, email):
"""Create contact based on given contact name"""
contact = contact.split(" ")
names = contact.split(" ")

contact = frappe.get_doc(
{
"doctype": "Contact",
"first_name": contact[0],
"last_name": len(contact) > 1 and contact[1] or "",
"first_name": names[0],
"middle_name": len(names) > 2 and " ".join(names[1:-1]) or "",
"last_name": len(names) > 1 and names[-1] or "",
"is_primary_contact": 1,
}
)
Expand Down Expand Up @@ -640,14 +641,28 @@ def get_credit_limit(customer, company):


def make_contact(args, is_primary_contact=1):
contact = frappe.get_doc(
{
"doctype": "Contact",
"first_name": args.get("customer_name"),
"is_primary_contact": is_primary_contact,
"links": [{"link_doctype": args.get("doctype"), "link_name": args.get("name")}],
}
)
values = {
"doctype": "Contact",
"is_primary_contact": is_primary_contact,
"links": [{"link_doctype": args.get("doctype"), "link_name": args.get("name")}],
}
if args.customer_type == "Individual":
names = args.get("customer_name").split(" ")
values.update(
{
"first_name": names[0],
"middle_name": len(names) > 2 and " ".join(names[1:-1]) or "",
"last_name": len(names) > 1 and names[-1] or "",
}
)
else:
values.update(
{
"company_name": args.get("customer_name"),
}
)
contact = frappe.get_doc(values)

if args.get("email_id"):
contact.add_email(args.get("email_id"), is_primary=True)
if args.get("mobile_no"):
Expand Down

0 comments on commit 9fde782

Please sign in to comment.