Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Anand Doshi 2012-11-26 18:48:11 +05:30
commit 58babf93c6
10 changed files with 182 additions and 174 deletions

View File

@ -25,11 +25,32 @@ MyProfile = function(wrapper) {
this.make = function() {
this.wrapper.appframe = new wn.ui.AppFrame($(this.wrapper).find('.layout-appframe'), 'Profile Settings');
this.wrapper.appframe.add_button('Update', this.update_profile);
this.wrapper.appframe.buttons["Update"].addClass("btn-info");
this.wrapper.appframe.add_button('Change Password', this.change_password);
this.wrapper.appframe.add_button('Change Background', this.change_background);
this.wrapper.appframe.add_label("Set Theme:");
this.wrapper.appframe.add_select("Theme",
keys(erpnext.themes).sort())
$(this.wrapper).find('.layout-main').html("<h4>Personal</h4>\
<div class='personal-settings' style='margin-left: 15px;'></div>\
<hr>\
<!--<h4>Email</h4>\
<div class='email-settings' style='margin-left: 15px;'></div>\
<hr>-->\
<h4>Display</h4>\
<div class='display-settings' style='margin-left: 15px;'>\
<p>Change Background: <button class='btn btn-small change-background'>Upload</button></p>\
<br><p>Change Theme: <select class='change-theme'></select></p>\
</div>");
this.make_display();
this.make_personal();
}
this.make_display = function() {
$(this.wrapper).find(".change-background")
.click(me.change_background)
$(this.wrapper).find(".change-theme")
.add_options(keys(erpnext.themes).sort())
.change(function() {
erpnext.set_theme($(this).val());
}).val(wn.boot.profile.defaults.theme ?
@ -42,16 +63,20 @@ MyProfile = function(wrapper) {
args: {theme: $(this).val() }
})
});
}
this.make_personal = function() {
this.personal = $(this.wrapper).find('.personal-settings').html('<div \
class="pull-left" style="width: 300px;">\
<img style="max-width: 200px;" src='+wn.user_info(user).image+'><br><br>\
<button class="btn btn-small">Change Image</button><br><br>\
</div><div class="pull-left profile-form" style="width: 45%; margin-top: -11px;">\
<div class="clear"></div>\
</div>')
this.tab = make_table($a($(this.wrapper).find('.layout-main').get(0), 'div', '', {marginTop:'19px'}),
1, 2, '90%', ['50%', '50%'], {padding:'11px'})
this.img = $a($td(this.tab, 0, 0), 'img', '', {width: '120px', maxHeight:'200px'});
this.img.src = wn.user_info(user).image;
$btn($a($td(this.tab, 0, 0), 'div', '', {marginTop:'11px'}), 'Change Image', this.change_image);
this.personal.find("button").click(this.change_image);
this.make_form();
this.load_details();
this.load_details();
}
this.load_details = function() {
@ -64,34 +89,30 @@ MyProfile = function(wrapper) {
// form
//
this.make_form = function() {
var div = $a($td(this.tab, 0, 1), 'div');
var div = this.personal.find(".profile-form").get(0);
this.form = new wn.ui.FieldGroup({
parent: div,
fields: [
{fieldname:'first_name', fieldtype:'Data',label:'First Name',reqd:1},
{fieldname:'last_name', fieldtype:'Data',label:'Last Name'},
{fieldname:'email_signature', fieldtype:'Text',label:'Email Signature',
{fieldname:'email_signature', fieldtype:'Small Text',label:'Email Signature',
decription:'Will be appended to outgoing mail'},
{fieldname:'bio', fieldtype:'Text',label:'Bio'},
{fieldname:'update', fieldtype:'Button',label:'Update'}
]
});
this.form.fields_dict.update.input.onclick = function() {
var v = me.form.get_values();
if(v) {
this.set_working();
var btn = this;
$c_page('home','profile_settings','set_user_details',v,function(r, rt) {
btn.done_working();
})
}
}
}
//
// change password
//
this.update_profile = function() {
var v = me.form.get_values();
if(v) {
$(this).set_working();
var btn = this;
$c_page('home','profile_settings','set_user_details',v,function(r, rt) {
$(btn).done_working();
})
}
}
this.change_password = function() {
var d = new wn.ui.Dialog({
title:'Change Password',
@ -137,7 +158,7 @@ MyProfile = function(wrapper) {
if(fid) {
d.hide();
wn.boot.user_info[user].image = 'files/' + fid;
pscript.myprofile.img.src = 'files/' + fid;
me.personal.find("img").attr("src", 'files/' + fid);
}
}
});

View File

@ -49,7 +49,8 @@ def get_user_details(arg=None):
"""
Returns user first name, last name and bio
"""
return webnotes.conn.sql("select first_name, last_name, bio from tabProfile where name=%s", webnotes.user.name, as_dict=1)[0]
return webnotes.conn.sql("""select first_name, last_name, bio, email_signature
from tabProfile where name=%s""", webnotes.user.name, as_dict=1)[0]
@webnotes.whitelist()
def set_user_details(arg=None):

View File

@ -0,0 +1,75 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
erpnext.CommunicationView = Class.extend({
init: function(opts) {
this.comm_list = [];
$.extend(this, opts);
this.list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified)
? -1 : 1 })
this.make();
},
make: function() {
var me = this;
this.make_body();
$.each(this.list, function(i, d) {
me.prepare(d);
me.make_line(d);
});
// show first
this.comm_list[0].find('.comm-content').toggle(true);
},
make_body: function() {
$(this.parent)
.html("")
.css({"margin":"10px 0px"});
this.wrapper = $("<div><h4>Communication History</h4>\
<button class='btn btn-small'>Add Reply</button></p></div>")
.appendTo(this.parent);
this.body = $("<table class='table table-bordered table-hover table-striped'>")
.appendTo(this.wrapper);
},
prepare: function(doc) {
//doc.when = comment_when(this.doc.modified);
doc.when = doc.modified;
if(doc.content.indexOf("<br>")== -1 && doc.content.indexOf("<p>")== -1) {
doc.content = doc.content.replace(/\n/g, "<br>");
}
doc.email_address = doc.email_address.replace(/</, "&lt;").replace(/>/, "&gt;");
doc.content = doc.content.split("=== In response to ===")[0];
doc.content = doc.content.split("-----Original Message-----")[0];
},
make_line: function(doc) {
var me = this;
var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
<p><b>%(email_address)s on %(when)s</b></p>\
<div class="comm-content" style="border-top: 1px solid #ddd; padding: 10px; \
display: none;"></div>\
</td></tr>', doc))
.appendTo(this.body)
.css({"cursor":"pointer"})
.click(function() {
$(this).find(".comm-content").toggle();
});
this.comm_list.push(comm);
comm.find(".comm-content").html(doc.content);
}
})

View File

@ -16,6 +16,8 @@
// Module CRM
wn.require("public/app/js/communication.js");
wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/support/doctype/communication/communication.js');
@ -41,8 +43,6 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(user=='Guest') doc.naming_series = 'WebLead';
cur_frm.add_fetch('customer', 'customer_name', 'company_name');
cur_frm.cscript.make_communication_body();
if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) {
cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query;
@ -67,32 +67,22 @@ cur_frm.cscript.refresh_custom_buttons = function(doc) {
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
// custom buttons
//---------------
cur_frm.cscript.refresh_custom_buttons(doc);
erpnext.hide_naming_series();
if (!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn);
new erpnext.CommunicationView({
list: wn.model.get("Communication", {"lead": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper
})
}
// Client Side Triggers
// ===========================================================
// ************ Status ******************
cur_frm.cscript.status = function(doc, cdt, cdn){
cur_frm.cscript.refresh(doc, cdt, cdn);
}
//Trigger in Item Table
//===================================
cur_frm.cscript.item_code=function(doc,cdt,cdn){
var d = locals[cdt][cdn];
if (d.item_code) { get_server_fields('get_item_detail',d.item_code,'lead_item_detail',doc,cdt,cdn,1);}
}
// Create New Customer
// ===============================================================
cur_frm.cscript['Create Customer'] = function(){
var doc = cur_frm.doc;
$c('runserverobj',args={ 'method':'check_status', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},

View File

@ -18,48 +18,28 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, msgprint, errprint
from webnotes.utils import cint, cstr, flt, validate_email_add
from webnotes.model.doc import Document, addchild
from webnotes import session, msgprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
from utilities.transaction_base import TransactionBase
class DocType:
class DocType(TransactionBase):
def __init__(self, doc, doclist):
self.doc = doc
self.doclist = doclist
#check status of lead
#------------------------
def onload(self):
self.add_communication_list()
def check_status(self):
chk = sql("select status from `tabLead` where name=%s", self.doc.name)
chk = chk and chk[0][0] or ''
return cstr(chk)
# Get item detail (will be removed later)
#=======================================
def get_item_detail(self,item_code):
it=sql("select item_name,brand,item_group,description,stock_uom from `tabItem` where name='%s'"%item_code)
if it:
ret = {
'item_name' : it and it[0][0] or '',
'brand' : it and it[0][1] or '',
'item_group' : it and it[0][2] or '',
'description': it and it[0][3] or '',
'uom' : it and it[0][4] or ''
}
return ret
def validate(self):
if self.doc.status == 'Lead Lost' and not self.doc.order_lost_reason:
@ -79,20 +59,6 @@ class DocType:
if self.doc.contact_date:
self.add_calendar_event()
if not self.doc.naming_series:
if session['user'] == 'Guest':
import webnotes.model.doctype
docfield = webnotes.model.doctype.get('Lead')
series = [d.options for d in docfield if d.doctype == 'DocField' and d.fieldname == 'naming_series']
if series:
sr = series[0].split("\n")
set(self.doc, 'naming_series', sr[0])
else:
msgprint("Please specify naming series")
raise Exception
# Add to Calendar
# ===========================================================================
def add_calendar_event(self):
# delete any earlier event by this lead
sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name)
@ -113,3 +79,9 @@ class DocType:
event_user = addchild(ev, 'event_individuals', 'Event User')
event_user.person = self.doc.contact_by
event_user.save()
def on_trash(self):
webnotes.conn.sql("""update tabCommunication set lead='' where lead=%s""",
self.doc.name)
webnotes.conn.sql("""update `tabSupport Ticket` set contact='' where contact=%s""",
self.doc.name)

View File

@ -4,7 +4,7 @@
"docstatus": 0,
"creation": "2012-11-02 17:16:46",
"modified_by": "Administrator",
"modified": "2012-11-26 11:12:27"
"modified": "2012-11-26 18:13:22"
},
{
"autoname": "naming_series:",
@ -200,7 +200,6 @@
},
{
"doctype": "DocField",
"label": "Communication History",
"fieldname": "communication_history",
"fieldtype": "Section Break",
"permlevel": 0

View File

@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require("public/app/js/communication.js");
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
$.extend(cur_frm.cscript, {
onload: function(doc, dt, dn) {
cur_frm.last_reload = new Date();
@ -22,8 +26,6 @@ $.extend(cur_frm.cscript, {
<p><a href="#Form/Email Settings/Email Settings">Email Settings</a><br>\
<span class="help">Integrate incoming support emails to Support Ticket</span></p>';
}
if(!doc.customer) hide_field(['customer_name','address_display','contact_display','contact_mobile','contact_email']);
},
refresh: function(doc) {
@ -53,19 +55,13 @@ $.extend(cur_frm.cscript, {
make_listing: function(doc) {
var wrapper = cur_frm.fields_dict['thread_html'].wrapper;
$(wrapper)
.html("")
.css({"margin":"10px 0px"});
var comm_list = wn.model.get("Communication", {"support_ticket": doc.name})
comm_list.push({
"email_address": doc.raised_by,
"modified": doc.creation,
"content": doc.description});
comm_list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified)
? -1 : 1 })
new erpnext.CommunicationView({
list: comm_list,
parent: wrapper
@ -89,8 +85,8 @@ $.extend(cur_frm.cscript, {
cur_frm.refresh();
}
}
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback);
if(doc.customer) unhide_field(['customer_name','address_display','contact_display','contact_mobile','contact_email']);
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name),
'get_default_customer_address', '', callback);
},
'Close Ticket': function() {
@ -116,52 +112,3 @@ $.extend(cur_frm.cscript, {
})
erpnext.CommunicationView = Class.extend({
init: function(opts) {
this.comm_list = [];
$.extend(this, opts);
this.make();
},
make: function() {
var me = this;
this.make_body();
$.each(this.list, function(i, d) {
me.prepare(d);
me.make_line(d);
});
// show first
this.comm_list[0].find('.comm-content').toggle(true);
},
make_body: function() {
this.body = $("<table class='table table-bordered table-hover table-striped'>").appendTo(this.parent);
},
prepare: function(doc) {
//doc.when = comment_when(this.doc.modified);
doc.when = doc.modified;
if(doc.content.indexOf("<br>")== -1 && doc.content.indexOf("<p>")== -1) {
doc.content = doc.content.replace(/\n/g, "<br>");
}
doc.email_address = doc.email_address.replace(/</, "&lt;").replace(/>/, "&gt;");
doc.content = doc.content.split("=== In response to ===")[0];
doc.content = doc.content.split("-----Original Message-----")[0];
},
make_line: function(doc) {
var me = this;
var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
<p><b>%(email_address)s on %(when)s</b></p>\
<div class="comm-content"></div>\
</td></tr>', doc))
.appendTo(this.body)
.css({"cursor":"pointer"})
.click(function() {
$(this).find(".comm-content").toggle();
});
this.comm_list.push(comm);
comm.find(".comm-content").html(doc.content);
}
})
cur_frm.fields_dict.allocated_to.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;

View File

@ -28,18 +28,6 @@ class DocType(TransactionBase):
def onload(self):
self.add_communication_list()
def add_communication_list(self):
# remove communications if present
self.doclist = webnotes.doclist(self.doclist).get({"doctype": ["!=", "Communcation"]})
comm_list = webnotes.conn.sql("""select * from tabCommunication
where support_ticket=%s order by modified desc limit 20""", self.doc.name, as_dict=1)
[d.update({"doctype":"Communication"}) for d in comm_list]
self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
for d in comm_list]))
def send_response(self):
"""

View File

@ -37,15 +37,9 @@ class DocType:
else:
self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '')
#----------------------
# Call to Validate
#----------------------
def validate(self):
self.validate_primary_contact()
#----------------------
# Validate that there can only be one primary contact for particular customer, supplier
#----------------------
def validate_primary_contact(self):
sql = webnotes.conn.sql
if self.doc.is_primary_contact == 1:
@ -65,3 +59,9 @@ class DocType:
elif self.doc.sales_partner:
if not sql("select name from tabContact where is_primary_contact=1 and sales_partner = '%s'" % (self.doc.sales_partner)):
self.doc.is_primary_contact = 1
def on_trash(self):
webnotes.conn.sql("""update tabCommunication set contact='' where contact=%s""",
self.doc.name)
webnotes.conn.sql("""update `tabSupport Ticket` set contact='' where contact=%s""",
self.doc.name)

View File

@ -241,3 +241,18 @@ class TransactionBase:
def get_formatted_message(self, args):
""" get formatted message for auto notification"""
return get_obj('Notification Control').get_formatted_message(args)
def add_communication_list(self):
# remove communications if present
self.doclist = webnotes.doclist(self.doclist).get({
"doctype": ["!=", "Communcation"]})
comm_list = webnotes.conn.sql("""select * from tabCommunication
where %s=%s order by modified desc limit 20""" \
% (self.doc.doctype.replace(" ", "_").lower(), "%s"),
self.doc.name, as_dict=1)
[d.update({"doctype":"Communication"}) for d in comm_list]
self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
for d in comm_list]))