[fix] address creation for new user
This commit is contained in:
parent
441b2c7657
commit
cc24d28ddc
@ -111,6 +111,9 @@ doc_events = {
|
|||||||
"Price List": {
|
"Price List": {
|
||||||
"on_update": "erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings"
|
"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 = {
|
scheduler_events = {
|
||||||
|
@ -280,6 +280,7 @@ def get_customer(user=None):
|
|||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
|
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
||||||
|
|
||||||
if customer:
|
if customer:
|
||||||
return frappe.get_doc("Customer", customer)
|
return frappe.get_doc("Customer", customer)
|
||||||
|
|
||||||
@ -320,6 +321,17 @@ def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_
|
|||||||
|
|
||||||
return address_docs
|
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()
|
@frappe.whitelist()
|
||||||
def apply_shipping_rule(shipping_rule):
|
def apply_shipping_rule(shipping_rule):
|
||||||
quotation = _get_cart_quotation()
|
quotation = _get_cart_quotation()
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<h4 class="strong">{{ doc.address_title }}</h4>
|
<h4 class="strong">{{ doc.address_title }}</h4>
|
||||||
<p class="text-muted small">
|
<p class="text-muted small">
|
||||||
{{ frappe.get_doc(doc).get_display() }}
|
{{ frappe.get_doc(doc).get_display() }}
|
||||||
</div>
|
</p>
|
||||||
</div>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,6 +10,9 @@ from frappe.utils import cstr
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class Address(Document):
|
class Address(Document):
|
||||||
|
def __setup__(self):
|
||||||
|
self.flags.linked = False
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
if not self.address_title:
|
if not self.address_title:
|
||||||
self.address_title = self.customer \
|
self.address_title = self.customer \
|
||||||
@ -42,13 +45,10 @@ class Address(Document):
|
|||||||
|
|
||||||
def link_address(self):
|
def link_address(self):
|
||||||
"""Link address based on owner"""
|
"""Link address based on owner"""
|
||||||
linked = False
|
if not self.flags.linked:
|
||||||
for fieldname in self.link_fields:
|
self.check_if_linked()
|
||||||
if self.get(fieldname):
|
|
||||||
linked = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not linked:
|
if not self.flags.linked:
|
||||||
contact = frappe.db.get_value("Contact", {"email_id": self.owner},
|
contact = frappe.db.get_value("Contact", {"email_id": self.owner},
|
||||||
("name", "customer", "supplier"), as_dict = True)
|
("name", "customer", "supplier"), as_dict = True)
|
||||||
if contact:
|
if contact:
|
||||||
@ -57,6 +57,11 @@ class Address(Document):
|
|||||||
|
|
||||||
self.lead = frappe.db.get_value("Lead", {"email_id": self.owner})
|
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):
|
def validate_shipping_address(self):
|
||||||
"""Validate that there can only be one shipping address for particular customer, supplier"""
|
"""Validate that there can only be one shipping address for particular customer, supplier"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user