[fix] address creation for new user
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 734aa59..22a093d 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -111,6 +111,9 @@
"Price List": {
"on_update": "erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings"
},
+ "Address": {
+ "validate": "erpnext.shopping_cart.cart.set_customer_in_address"
+ }
}
scheduler_events = {
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index c116bdc..561a50c 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -280,6 +280,7 @@
user = frappe.session.user
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
+
if customer:
return frappe.get_doc("Customer", customer)
@@ -320,6 +321,17 @@
return address_docs
+def set_customer_in_address(doc, method=None):
+ if doc.flags.linked:
+ return
+
+ doc.check_if_linked()
+
+ if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
+ # creates a customer if one does not exist
+ get_customer()
+ doc.link_address()
+
@frappe.whitelist()
def apply_shipping_rule(shipping_rule):
quotation = _get_cart_quotation()
diff --git a/erpnext/templates/includes/address_row.html b/erpnext/templates/includes/address_row.html
index 717ca75..f6ec819 100644
--- a/erpnext/templates/includes/address_row.html
+++ b/erpnext/templates/includes/address_row.html
@@ -3,7 +3,6 @@
<h4 class="strong">{{ doc.address_title }}</h4>
<p class="text-muted small">
{{ frappe.get_doc(doc).get_display() }}
- </div>
- </div>
+ </p>
</a>
</div>
diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py
index a482891..da529fb 100644
--- a/erpnext/utilities/doctype/address/address.py
+++ b/erpnext/utilities/doctype/address/address.py
@@ -10,6 +10,9 @@
from frappe.model.document import Document
class Address(Document):
+ def __setup__(self):
+ self.flags.linked = False
+
def autoname(self):
if not self.address_title:
self.address_title = self.customer \
@@ -42,13 +45,10 @@
def link_address(self):
"""Link address based on owner"""
- linked = False
- for fieldname in self.link_fields:
- if self.get(fieldname):
- linked = True
- break
+ if not self.flags.linked:
+ self.check_if_linked()
- if not linked:
+ if not self.flags.linked:
contact = frappe.db.get_value("Contact", {"email_id": self.owner},
("name", "customer", "supplier"), as_dict = True)
if contact:
@@ -57,6 +57,11 @@
self.lead = frappe.db.get_value("Lead", {"email_id": self.owner})
+ def check_if_linked(self):
+ for fieldname in self.link_fields:
+ if self.get(fieldname):
+ self.flags.linked = True
+ break
def validate_shipping_address(self):
"""Validate that there can only be one shipping address for particular customer, supplier"""