[fix] edit-profile in frappe;
This commit is contained in:
parent
72b4ad8155
commit
2d985e1973
@ -124,7 +124,8 @@ doc_events = {
|
||||
},
|
||||
"User": {
|
||||
"validate": "erpnext.hr.doctype.employee.employee.validate_employee_role",
|
||||
"on_update": "erpnext.hr.doctype.employee.employee.update_user_permissions"
|
||||
"on_update": "erpnext.hr.doctype.employee.employee.update_user_permissions",
|
||||
"on_update": "erpnext.utilities.doctype.contact.contact.update_contact"
|
||||
},
|
||||
"Sales Taxes and Charges Template": {
|
||||
"on_update": "erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings"
|
||||
|
@ -1,55 +0,0 @@
|
||||
{% extends "templates/web.html" %}
|
||||
|
||||
{% block title %} {{ "My Profile" }} {% endblock %}
|
||||
|
||||
{% block header %}<h2>My Profile</h2>{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
<div class="user-content" style="max-width: 500px;">
|
||||
<div class="alert alert-warning" id="message" style="display: none;"></div>
|
||||
<form>
|
||||
<fieldset>
|
||||
<label>Full Name</label>
|
||||
<input class="form-control" type="text" id="fullname" placeholder="Your Name">
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>Company Name</label>
|
||||
<input class="form-control" type="text" id="company_name" placeholder="Company Name" value="{{ company_name }}">
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>Mobile No</label>
|
||||
<input class="form-control" type="text" id="mobile_no" placeholder="Mobile No" value="{{ mobile_no }}">
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>Phone</label>
|
||||
<input class="form-control" type="text" id="phone" placeholder="Phone" value="{{ phone }}">
|
||||
</fieldset>
|
||||
<button id="update_user" type="submit" class="btn btn-default">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
frappe.ready(function() {
|
||||
$("#fullname").val(getCookie("full_name") || "");
|
||||
$("#update_user").click(function() {
|
||||
frappe.call({
|
||||
method: "erpnext.templates.pages.edit_profile.update_user",
|
||||
type: "POST",
|
||||
args: {
|
||||
fullname: $("#fullname").val(),
|
||||
company_name: $("#company_name").val(),
|
||||
mobile_no: $("#mobile_no").val(),
|
||||
phone: $("#phone").val()
|
||||
},
|
||||
btn: this,
|
||||
msg: $("#message"),
|
||||
callback: function(r) {
|
||||
if(!r.exc) $("#user-full-name").html($("#fullname").val());
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<!-- no-sidebar -->
|
||||
{% endblock %}
|
||||
|
@ -1,35 +0,0 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import cstr
|
||||
from erpnext.shopping_cart.cart import get_customer
|
||||
|
||||
no_cache = 1
|
||||
no_sitemap = 1
|
||||
|
||||
def get_context(context):
|
||||
party = get_customer()
|
||||
mobile_no, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
|
||||
"customer": party.name}, ["mobile_no", "phone"])
|
||||
|
||||
return {
|
||||
"company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name),
|
||||
"mobile_no": cstr(mobile_no),
|
||||
"phone": cstr(phone)
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_user(fullname, password=None, company_name=None, mobile_no=None, phone=None):
|
||||
from erpnext.shopping_cart.cart import update_party
|
||||
update_party(fullname, company_name, mobile_no, phone)
|
||||
|
||||
if not fullname:
|
||||
return _("Name is required")
|
||||
|
||||
frappe.db.set_value("User", frappe.session.user, "first_name", fullname)
|
||||
frappe.local.cookie_manager.set_cookie("full_name", fullname)
|
||||
|
||||
return _("Updated")
|
@ -92,3 +92,13 @@ def get_contact_details(contact):
|
||||
"contact_department": contact.get("department")
|
||||
}
|
||||
return out
|
||||
|
||||
def update_contact(doc, method):
|
||||
'''Update contact when user is updated, if contact is found. Called via hooks'''
|
||||
contact_name = frappe.db.get_value("Contact", {"email_id": doc.name})
|
||||
if contact_name:
|
||||
contact = frappe.get_doc("Contact", contact_name)
|
||||
contact.first_name = doc.first_name
|
||||
contact.last_name = doc.last_name
|
||||
contact.phone = doc.phone
|
||||
contact.save(ignore_permissions=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user