From 703e4f4f5da73fc56ef1ff805864f065c9db455f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 20 Jun 2023 14:39:47 +0530 Subject: [PATCH] fix: Duplicate addresses are creating while using the E-commerce --- erpnext/e_commerce/shopping_cart/cart.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/e_commerce/shopping_cart/cart.py b/erpnext/e_commerce/shopping_cart/cart.py index 4c823936848..4f9088e8c08 100644 --- a/erpnext/e_commerce/shopping_cart/cart.py +++ b/erpnext/e_commerce/shopping_cart/cart.py @@ -3,7 +3,7 @@ import frappe import frappe.defaults -from frappe import _, throw +from frappe import _, bold, throw from frappe.contacts.doctype.address.address import get_address_display from frappe.contacts.doctype.contact.contact import get_contact_name from frappe.utils import cint, cstr, flt, get_fullname @@ -201,6 +201,11 @@ def get_shopping_cart_menu(context=None): @frappe.whitelist() def add_new_address(doc): doc = frappe.parse_json(doc) + address_title = doc.get("address_title") + if frappe.db.exists("Address", {"address_title": address_title}): + msg = f"The address with the title {bold(address_title)} already exists. Please change the title accordingly." + frappe.throw(_(msg), title=_("Address Already Exists")) + doc.update({"doctype": "Address"}) address = frappe.get_doc(doc) address.save(ignore_permissions=True)