[lead] [address] store lead address in Address doctype, with link field=lead

This commit is contained in:
Anand Doshi
2013-06-28 19:18:33 +05:30
parent b78a4e0f80
commit 8f9f8a43c7
14 changed files with 287 additions and 216 deletions

View File

@@ -14,78 +14,79 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Module CRM
wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/contact_control/contact_control.js');
cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(user =='Guest'){
hide_field(['status', 'naming_series', 'order_lost_reason',
'customer', 'rating', 'fax', 'website', 'territory',
'address_line1', 'address_line2', 'city', 'state',
'country', 'pincode', 'address', 'lead_owner', 'market_segment',
'industry', 'campaign_name', 'interested_in', 'company',
'fiscal_year', 'contact_by', 'contact_date', 'last_contact_date',
'contact_date_ref', 'to_discuss', 'more_info', 'follow_up',
'communication_history', 'cc_to', 'subject', 'message', 'lead_attachment_detail',
'Create Customer', 'Create Opportunity', 'transaction_date', 'type', 'source']);
doc.source = 'Website';
}
if(!doc.status) set_multiple(dt,dn,{status:'Open'});
if (!doc.date){
doc.date = date.obj_to_str(new Date());
}
// set naming series
if(user=='Guest') doc.naming_series = 'WebLead';
wn.provide("erpnext");
erpnext.LeadController = wn.ui.form.Controller.extend({
setup: function() {
this.frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
},
cur_frm.add_fetch('customer', 'customer_name', 'company_name');
if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) {
cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query;
}
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
}
if(in_list(user_roles,'System Manager')) {
cur_frm.footer.help_area.innerHTML = '<hr>\
<p><a href="#Form/Sales Email Settings">Sales Email Settings</a><br>\
<span class="help">Automatically extract Leads from a mail box e.g. "sales@example.com"</span></p>';
}
}
cur_frm.cscript.refresh_custom_buttons = function(doc) {
cur_frm.clear_custom_buttons();
if(!doc.__islocal && !in_list(['Converted', 'Lead Lost'], doc.status)) {
if (doc.source != 'Existing Customer') {
cur_frm.add_custom_button('Create Customer',
cur_frm.cscript['Create Customer']);
onload: function() {
if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) {
cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query;
}
cur_frm.add_custom_button('Create Opportunity',
cur_frm.cscript['Create Opportunity']);
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
}
if(in_list(user_roles,'System Manager')) {
cur_frm.footer.help_area.innerHTML = '<hr>\
<p><a href="#Form/Sales Email Settings">Sales Email Settings</a><br>\
<span class="help">Automatically extract Leads from a mail box e.g. "sales@example.com"</span></p>';
}
},
refresh: function() {
erpnext.hide_naming_series();
this.frm.clear_custom_buttons();
this.frm.__is_customer = this.frm.__is_customer || this.frm.doc.__is_customer;
if(!this.frm.doc.__islocal && !this.frm.__is_customer) {
this.frm.add_custom_button("Create Customer", this.frm.cscript['Create Customer']);
this.frm.add_custom_button("Create Opportunity", this.frm.cscript['Create Opportunity']);
this.frm.add_custom_button("Send SMS", this.frm.cscript.send_sms);
}
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"lead": this.frm.doc.name}),
parent: this.frm.fields_dict.communication_html.wrapper,
doc: this.frm.doc,
recipients: this.frm.doc.email_id
});
if(!this.frm.doc.__islocal) {
this.make_address_list();
}
},
make_address_list: function() {
var me = this;
if(!this.frm.address_list) {
this.frm.address_list = new wn.ui.Listing({
parent: this.frm.fields_dict['address_html'].wrapper,
page_length: 5,
new_doctype: "Address",
get_query: function() {
return 'select name, address_type, address_line1, address_line2, \
city, state, country, pincode, fax, email_id, phone, \
is_primary_address, is_shipping_address from tabAddress \
where lead="'+me.frm.doc.name+'" and docstatus != 2 \
order by is_primary_address, is_shipping_address desc'
},
as_dict: 1,
no_results_message: 'No addresses created',
render_row: this.render_address_row,
});
// note: render_address_row is defined in contact_control.js
}
this.frm.address_list.run();
}
}
});
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.cscript.refresh_custom_buttons(doc);
erpnext.hide_naming_series();
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"lead": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,
doc: doc,
recipients: doc.email_id
})
}
cur_frm.cscript.status = function(doc, cdt, cdn){
cur_frm.cscript.refresh(doc, cdt, cdn);
}
$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm}));
cur_frm.cscript['Create Customer'] = function(){
var doc = cur_frm.doc;
@@ -147,11 +148,4 @@ cur_frm.cscript['Create Opportunity'] = function(){
}
}
);
}
//get query select Territory
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
}

View File

@@ -38,6 +38,9 @@ class DocType(SellingController):
def onload(self):
self.add_communication_list()
customer = webnotes.conn.get_value("Customer", {"lead_name": self.doc.name})
if customer:
self.doc.fields["__is_customer"] = customer
def on_communication_sent(self, comm):
webnotes.conn.set(self.doc, 'status', 'Replied')

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-04-10 11:45:37",
"docstatus": 0,
"modified": "2013-06-14 16:20:17",
"modified": "2013-06-28 15:08:26",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -164,9 +164,33 @@
"doctype": "DocField",
"fieldname": "contact_info",
"fieldtype": "Section Break",
"label": "Contact Info",
"label": "Address & Contact",
"oldfieldtype": "Column Break"
},
{
"depends_on": "eval:doc.__islocal",
"doctype": "DocField",
"fieldname": "address_desc",
"fieldtype": "HTML",
"hidden": 0,
"label": "Address Desc",
"options": "<em>Addresses will appear only when you save the lead</em>",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "address_html",
"fieldtype": "HTML",
"hidden": 0,
"label": "Address HTML",
"print_hide": 0,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "column_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "remark",
@@ -219,70 +243,6 @@
"options": "Territory",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "column_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "address_line1",
"fieldtype": "Data",
"label": "Address Line 1",
"oldfieldname": "address_line1",
"oldfieldtype": "Data",
"print_hide": 1,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "address_line2",
"fieldtype": "Data",
"label": "Address Line 2",
"oldfieldname": "address_line2",
"oldfieldtype": "Data",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "city",
"fieldtype": "Data",
"label": "City",
"oldfieldname": "city",
"oldfieldtype": "Select",
"print_hide": 1,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "country",
"fieldtype": "Select",
"label": "Country",
"oldfieldname": "country",
"oldfieldtype": "Select",
"options": "link:Country",
"print_hide": 1,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "state",
"fieldtype": "Data",
"label": "State",
"oldfieldname": "state",
"oldfieldtype": "Select",
"options": "Suggest",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "pincode",
"fieldtype": "Data",
"label": "Pin Code",
"oldfieldname": "pincode",
"oldfieldtype": "Data",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "more_info",

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:08",
"docstatus": 0,
"modified": "2013-06-27 11:31:49",
"modified": "2013-06-28 12:47:10",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -690,6 +690,24 @@
"reqd": 0,
"search_index": 0
},
{
"doctype": "DocField",
"fieldname": "shipping_address_name",
"fieldtype": "Link",
"hidden": 0,
"label": "Shipping Address Name",
"options": "Address",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "shipping_address",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Shipping Address",
"print_hide": 1,
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",

View File

@@ -27,6 +27,9 @@ wn.require("app/js/transaction.js");
erpnext.selling.SellingController = erpnext.TransactionController.extend({
setup: function() {
this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate");
if(this.frm.fields_dict.shipping_address_name && this.frm.fields_dict.customer_address)
this.frm.fields_dict.shipping_address_name.get_query = this.frm.fields_dict['customer_address'].get_query;
},
onload: function() {
@@ -476,6 +479,27 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
});
},
shipping_address_name: function () {
var me = this;
if(this.frm.doc.shipping_address_name) {
wn.model.with_doc("Address", this.frm.doc.shipping_address_name, function(name) {
var address = wn.model.get_doc("Address", name);
var out = $.map(["address_line1", "address_line2", "city"],
function(f) { return address[f]; });
var state_pincode = $.map(["state", "pincode"], function(f) { return address[f]; }).join(" ");
if(state_pincode) out.push(state_pincode);
if(address["country"]) out.push(address["country"]);
out.concat($.map([["Phone:", address["phone"]], ["Fax:", address["fax"]]],
function(val) { return val[1] ? val.join(" ") : null; }));
me.frm.set_value("shipping_address", out.join("\n"));
});
}
}
});
// to save previous state of cur_frm.cscript

View File

@@ -79,29 +79,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
cur_frm.fields_dict.shipping_address_name.get_query = cur_frm.fields_dict['customer_address'].get_query;
cur_frm.cscript.shipping_address_name = function() {
if(cur_frm.doc.shipping_address_name) {
wn.model.with_doc("Address", cur_frm.doc.shipping_address_name, function(name) {
var address = wn.model.get_doc("Address", name);
var out = $.map(["address_line1", "address_line2", "city"],
function(f) { return address[f]; });
var state_pincode = $.map(["state", "pincode"], function(f) { return address[f]; }).join(" ");
if(state_pincode) out.push(state_pincode);
if(address["country"]) out.push(address["country"]);
out.concat($.map([["Phone:", address["phone"]], ["Fax:", address["fax"]]],
function(val) { return val[1] ? val.join(" ") : null; }));
cur_frm.set_value("shipping_address", out.join("\n"));
});
}
};
cur_frm.cscript.pull_quotation_details = function(doc,dt,dn) {
var callback = function(r,rt){
var doc = locals[cur_frm.doctype][cur_frm.docname];