webnotes.model.doctype (new version)

This commit is contained in:
Rushabh Mehta
2012-11-29 11:49:56 +05:30
parent a5d18706b7
commit d7fe2bfe1b
18 changed files with 15 additions and 842 deletions

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,142 +0,0 @@
cur_frm.cscript.onload = function(doc) {
cur_frm.fields_dict.user.get_query = function() {
return "select name, concat_ws(' ', first_name, middle_name, last_name) \
from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
(%(key)s like \"%s\" or \
concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
limit 50";
};
cur_frm.fields_dict.lead.get_query = function() {
return "select name, lead_name from `tabLead` \
where docstatus < 2 and \
(%(key)s like \"%s\" or lead_name like \"%%%s\" or \
company_name like \"%%%s\") \
order by lead_name asc limit 50";
};
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
}
cur_frm.cscript.refresh = function(doc, dt, dn) {
if(!doc.__islocal) {
var field_list = ['lead', 'customer', 'supplier', 'contact', 'opportunity',
'quotation', 'support_ticket'];
var hide_list = [];
$.each(field_list, function(i, v) {
if(!doc[v]) hide_list.push(v);
});
if(hide_list.length < field_list.length) hide_field(hide_list);
}
}
cur_frm.cscript.make_communication_body = function() {
var communication_wrapper = cur_frm.fields_dict.communication_html.wrapper;
communication_wrapper.innerHTML = '';
cur_frm.communication_html = $a(communication_wrapper, 'div');
$(cur_frm.communication_html).css({
'min-height': '275px',
});
}
cur_frm.cscript.render_communication_list = function(doc, dt, dn) {
var ListView = wn.views.ListView.extend({
init: function(doclistview) {
this._super(doclistview);
this.fields = this.fields.concat([
"`tabCommunication`.communication_date",
"`tabCommunication`.category",
"`tabCommunication`.subject",
"`tabCommunication`.content"
]);
this.order_by = "`tabCommunication`.communication_date desc";
},
prepare_data: function(data) {
this._super(data);
this.prepare_when(data, data.creation);
// escape double quote
data.content = cstr(data.subject).replace(/"/gi, '\"')
+ " | " + cstr(data.content).replace(/"/gi, '\"');
if(data.content && data.content.length > 50) {
data.content = '<span title="'+data.content+'">' +
data.content.substr(0,50) + '...</span>';
}
},
columns: [
{width: '3%', content: 'docstatus'},
{width: '15%', content: 'name'},
{width: '15%', content: 'category'},
{width: '55%', content: 'content'},
{width: '12%', content:'when',
css: {'text-align': 'right', 'color':'#777'}}
],
});
cur_frm.cscript.render_list(doc, 'Communication', cur_frm.communication_html,
ListView, function(doctype) {
var new_doc = LocalDB.create(doctype);
new_doc = locals[doctype][new_doc];
new_doc[doc.doctype.toLowerCase().replace(" ", "_")] = doc.name;
loaddoc(new_doc.doctype, new_doc.name);
});
}
// Render List
cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView, make_new_doc) {
wn.model.with_doctype(doctype, function(r) {
if((r && r['403']) || wn.boot.profile.all_read.indexOf(doctype)===-1) {
return;
}
var RecordListView = wn.views.RecordListView.extend({
default_docstatus: ['0', '1', '2'],
default_filters: [
[doctype, doc.doctype.toLowerCase().replace(" ", "_"), '=', doc.name],
],
});
if (make_new_doc) {
RecordListView = RecordListView.extend({
make_new_doc: make_new_doc,
});
}
var record_list_view = new RecordListView(doctype, wrapper, ListView);
if (!cur_frm[doctype.toLowerCase().replace(" ", "_") + "_list"]) {
cur_frm[doctype.toLowerCase().replace(" ", "_") + "_list"] = record_list_view;
}
});
}
cur_frm.cscript.contact = function(doc, dt, dn) {
if (doc.contact) {
wn.call({
method: 'support.doctype.communication.communication.get_customer_supplier',
args: {
contact: doc.contact
},
callback: function(r, rt) {
if (!r.exc && r.message) {
doc = locals[doc.doctype][doc.name];
doc[r.message['fieldname']] = r.message['value'];
refresh_field(r.message['fieldname']);
}
},
});
}
}
cur_frm.cscript.hide_dialog = function() {
if(cur_frm.communication_list)
cur_frm.communication_list.run();
}

View File

@@ -1,110 +0,0 @@
# 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/>.
from __future__ import unicode_literals
import webnotes
from webnotes.model.doc import make_autoname
@webnotes.whitelist()
def get_customer_supplier(args=None):
"""
Get Customer/Supplier, given a contact, if a unique match exists
"""
import webnotes
if not args: args = webnotes.form_dict
if not args.get('contact'):
raise Exception, "Please specify a contact to fetch Customer/Supplier"
result = webnotes.conn.sql("""\
select customer, supplier
from `tabContact`
where name = %s""", args.get('contact'), as_dict=1)
if result and len(result)==1 and (result[0]['customer'] or result[0]['supplier']):
return {
'fieldname': result[0]['customer'] and 'customer' or 'supplier',
'value': result[0]['customer'] or result[0]['supplier']
}
return {}
@webnotes.whitelist()
def make(doctype=None, name=None, content=None, subject=None,
sender=None, recipients=None, contact=None, lead=None,
communication_medium="Email", send_email=False):
# add to Communication
sent_via = None
d = webnotes.doc('Communication')
d.subject = subject
d.content = content
d.sender = sender or webnotes.conn.get_value("Profile", webnotes.session.user, "email")
d.recipients = recipients
d.lead = lead
d.contact = contact
if doctype:
sent_via = webnotes.get_obj(doctype, name)
d.fields[doctype.replace(" ", "_").lower()] = name
set_lead_and_contact(d)
d.communication_medium = communication_medium
if send_email:
send_comm_email(d, sent_via)
d.save(1)
def send_comm_email(d, sent_via=None):
from webnotes.utils.email_lib import sendmail
if sent_via:
if hasattr(sent_via, "get_sender"):
d.sender = sent_via.get_sender(d)
if hasattr(sent_via, "get_subject"):
d.subject = sent_via.get_subject(d)
if hasattr(sent_via, "get_content"):
d.content = sent_via.get_content(d)
sendmail(\
recipients = d.recipients.split(","), \
sender = d.sender, \
subject = d.subject, \
msg= d.content)
if sent_via and hasattr(sent_via, 'on_communication_sent'):
sent_via.on_communication_sent(d)
def set_lead_and_contact(d):
import email.utils
email_addr = email.utils.parseaddr(d.sender)
# set contact
if not d.contact:
d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]}, "name") or None
if not d.lead:
d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]}, "name") or None
if not d.lead and not d.contact:
d.lead = make_lead(d, email_addr[0])
def make_lead(d, real_name):
lead = webnotes.doc("Lead")
lead.lead_name = real_name or d.sender
lead.email_id = d.sender
lead.source = "Email"
lead.save(1)
return lead.name
class DocType():
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist

View File

@@ -1,347 +0,0 @@
[
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-11-14 12:25:16",
"modified_by": "Administrator",
"modified": "2012-11-27 18:51:01"
},
{
"autoname": "naming_series:",
"allow_attach": 1,
"name": "__common__",
"doctype": "DocType",
"module": "Support",
"in_dialog": 0,
"document_type": "Master",
"description": "Keep a track of all communications"
},
{
"name": "__common__",
"parent": "Communication",
"doctype": "DocField",
"parenttype": "DocType",
"parentfield": "fields"
},
{
"name": "__common__",
"parent": "Communication",
"read": 1,
"doctype": "DocPerm",
"write": 1,
"parenttype": "DocType",
"parentfield": "permissions"
},
{
"name": "Communication",
"doctype": "DocType"
},
{
"doctype": "DocField",
"label": "Basic Info",
"fieldname": "basic_info",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"default": "COMM-",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Naming Series",
"options": "COMM-",
"fieldname": "naming_series",
"fieldtype": "Select",
"hidden": 1,
"permlevel": 0
},
{
"colour": "White:FFF",
"doctype": "DocField",
"label": "Subject",
"fieldname": "subject",
"fieldtype": "Data",
"reqd": 1,
"permlevel": 0
},
{
"colour": "White:FFF",
"doctype": "DocField",
"label": "Content",
"width": "400",
"fieldname": "content",
"fieldtype": "Text Editor",
"reqd": 0,
"permlevel": 0
},
{
"doctype": "DocField",
"options": "simple",
"fieldname": "section_break1",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Category",
"options": "\nSales\nComplaint\nHelp\nSuggestion\nMiscellaneous\nSent Mail",
"fieldname": "category",
"fieldtype": "Select",
"reqd": 0,
"permlevel": 0
},
{
"doctype": "DocField",
"fieldname": "column_break2",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Next Communcation On",
"fieldname": "next_communication_date",
"fieldtype": "Date",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Action",
"options": "\nCreated Opportunity\nSent Quotation\nCreated Support Ticket\nCreated Customer Issue\nNo Action\nSent Mail",
"fieldname": "action",
"fieldtype": "Select",
"reqd": 0,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Additional Info",
"fieldname": "additional_info",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"colour": "White:FFF",
"doctype": "DocField",
"fieldname": "column_break3",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Lead",
"options": "Lead",
"fieldname": "lead",
"fieldtype": "Link",
"hidden": 0,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Contact",
"options": "Contact",
"fieldname": "contact",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Customer",
"options": "Customer",
"fieldname": "customer",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Supplier",
"options": "Supplier",
"fieldname": "supplier",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Opportunity",
"options": "Opportunity",
"fieldname": "opportunity",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Quotation",
"options": "Quotation",
"fieldname": "quotation",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Support Ticket",
"options": "Support Ticket",
"fieldname": "support_ticket",
"fieldtype": "Link",
"permlevel": 0
},
{
"doctype": "DocField",
"fieldname": "column_break1",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Recipients",
"fieldname": "recipients",
"fieldtype": "Data",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Sender",
"fieldname": "sender",
"fieldtype": "Data",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Communication Medium",
"options": "\nChat\nPhone\nEmail\nSMS\nVisit\nOther",
"fieldname": "communication_medium",
"fieldtype": "Select",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Phone No.",
"fieldname": "phone_no",
"fieldtype": "Data",
"permlevel": 0
},
{
"doctype": "DocField",
"options": "simple",
"fieldname": "section_break2",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "By",
"fieldname": "column_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"default": "__user",
"colour": "White:FFF",
"doctype": "DocField",
"label": "User",
"options": "Profile",
"fieldname": "user",
"fieldtype": "Link",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "Sales Person",
"options": "Sales Person",
"fieldname": "sales_person",
"fieldtype": "Link",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "On",
"fieldname": "column_break5",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"default": "Today",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Date",
"fieldname": "communication_date",
"fieldtype": "Date",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"doctype": "DocField",
"label": "File List",
"fieldname": "file_list",
"fieldtype": "Text",
"hidden": 1,
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"doctype": "DocField",
"label": "User Tags",
"fieldname": "_user_tags",
"fieldtype": "Data",
"hidden": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 1,
"doctype": "DocPerm",
"submit": 0,
"role": "Support Team",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 1,
"doctype": "DocPerm",
"submit": 0,
"role": "Sales Manager",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 1,
"doctype": "DocPerm",
"submit": 0,
"role": "Sales User",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"role": "Sales Manager",
"cancel": 0,
"permlevel": 1
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"role": "Support Manager",
"cancel": 0,
"permlevel": 1
},
{
"create": 1,
"doctype": "DocPerm",
"role": "Support Manager",
"cancel": 1,
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"role": "System Manager",
"cancel": 1,
"permlevel": 0
}
]

View File

@@ -1,43 +0,0 @@
wn.doclistviews['Communication'] = wn.views.ListView.extend({
init: function(doclistview) {
this._super(doclistview);
this.fields = this.fields.concat([
"`tabCommunication`.creation",
"`tabCommunication`.category",
"`tabCommunication`.subject",
"`tabCommunication`.content"
]);
this.order_by = "`tabCommunication`.creation desc";
this.stats = this.stats.concat(['category']);
},
prepare_data: function(data) {
this._super(data);
this.prepare_when(data, data.creation);
// escape double quote
data.content = cstr(data.subject)
+ " | " + cstr(data.content);
data.content = data.content.replace(/"/gi, '\"')
.replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
if(data.content && data.content.length > 50) {
data.content = '<span title="'+data.content+'">' +
data.content.substr(0,50) + '...</span>';
}
},
columns: [
{width: '3%', content: 'check'},
{width: '5%', content: 'avatar'},
{width: '15%', content: 'name'},
{width: '15%', content: 'category'},
{width: '55%', content: 'content+tags'},
{width: '12%', content:'when',
css: {'text-align': 'right', 'color':'#777'}}
],
make_new_doc: function(new_doctype) {
new_doc(new_doctype, 1);
}
});

View File

@@ -14,8 +14,6 @@
// 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, {
@@ -62,7 +60,7 @@ $.extend(cur_frm.cscript, {
"modified": doc.creation,
"content": doc.description});
cur_frm.communication_view = new erpnext.CommunicationView({
cur_frm.communication_view = new wn.views.CommunicationList({
list: comm_list,
parent: wrapper,
doc: doc,