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

Fix: prevent overriding of the existing customer during new signups #1331

Merged
merged 1 commit into from
May 28, 2021
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
35 changes: 17 additions & 18 deletions erpnext/shopping_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,28 +485,24 @@ def get_party(user=None):

fullname = get_fullname(user)
contact = frappe.db.get_value("Contact Email", {"email_id": user}, "parent")
customer = frappe.db.get_value("Customer", {"customer_name": fullname}, "name")

if not customer:
customer = frappe.new_doc("Customer")
customer = frappe.new_doc("Customer")
customer.update({
"customer_name": fullname,
"customer_type": "Individual",
"customer_group": get_shopping_cart_settings().default_customer_group,
"territory": get_root_of("Territory"),
"customer_primary_contact": contact
})

if debtors_account:
customer.update({
"customer_name": fullname,
"customer_type": "Individual",
"customer_group": get_shopping_cart_settings().default_customer_group,
"territory": get_root_of("Territory"),
"customer_primary_contact": contact
"accounts": [{
"company": cart_settings.company,
"account": debtors_account
}]
})

if debtors_account:
customer.update({
"accounts": [{
"company": cart_settings.company,
"account": debtors_account
}]
})
else:
customer = frappe.get_doc("Customer", customer)

customer.customer_primary_contact = contact
customer.flags.ignore_mandatory = True
customer.save(ignore_permissions=True)
Expand All @@ -524,6 +520,9 @@ def get_party(user=None):
contact.flags.ignore_mandatory = True
contact.save(ignore_permissions=True)

if not customer.customer_primary_contact:
customer.customer_primary_contact = contact.name

return customer

def _get_customer_or_lead(contact):
Expand Down