diff --git a/accounts/doctype/sales_invoice/sales_invoice.txt b/accounts/doctype/sales_invoice/sales_invoice.txt
index 27a0340f90..81b078528e 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.txt
+++ b/accounts/doctype/sales_invoice/sales_invoice.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:05",
"docstatus": 0,
- "modified": "2013-06-12 15:14:00",
+ "modified": "2013-06-27 11:35:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -432,7 +432,7 @@
"doctype": "DocField",
"fieldname": "charge",
"fieldtype": "Link",
- "label": "Taxes and Charges",
+ "label": "Apply Taxes and Charges Master",
"oldfieldname": "charge",
"oldfieldtype": "Link",
"options": "Sales Taxes and Charges Master",
@@ -446,10 +446,11 @@
},
{
"doctype": "DocField",
- "fieldname": "get_charges",
- "fieldtype": "Button",
- "label": "Get Taxes and Charges",
+ "fieldname": "shipping_rule",
+ "fieldtype": "Link",
+ "label": "Apply Shipping Rule",
"oldfieldtype": "Button",
+ "options": "Shipping Rule",
"print_hide": 1,
"read_only": 0
},
diff --git a/accounts/utils.py b/accounts/utils.py
index fa93cb0628..4ca1b3a57a 100644
--- a/accounts/utils.py
+++ b/accounts/utils.py
@@ -351,4 +351,4 @@ def fix_total_debit_credit():
webnotes.conn.sql("""update `tabGL Entry` set %s = %s + %s
where voucher_type = %s and voucher_no = %s and %s > 0 limit 1""" %
(dr_or_cr, dr_or_cr, '%s', '%s', '%s', dr_or_cr),
- (d.diff, d.voucher_type, d.voucher_no), debug=1)
\ No newline at end of file
+ (d.diff, d.voucher_type, d.voucher_no))
\ No newline at end of file
diff --git a/controllers/js/contact_address_common.js b/controllers/js/contact_address_common.js
index 89b1d43ac5..de1ab3478f 100644
--- a/controllers/js/contact_address_common.js
+++ b/controllers/js/contact_address_common.js
@@ -5,6 +5,11 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
+ if(cur_frm.fields_dict.lead) {
+ cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query;
+ cur_frm.add_fetch('lead', 'lead_name', 'lead_name');
+ }
+
if(doc.__islocal) {
var last_route = wn.route_history.slice(-2, -1)[0];
if(last_route && last_route[0]==="Form") {
@@ -13,10 +18,13 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
"Maintenance Schedule"]
.indexOf(last_route[1])!==-1) {
var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
- cur_frm.set_value("customer", refdoc.customer || refdoc.name);
- cur_frm.set_value("customer_name", refdoc.customer_name);
- if(cur_frm.doc.doctype==="Address")
- cur_frm.set_value("address_title", cur_frm.doc.customer)
+
+ if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) {
+ cur_frm.set_value("customer", refdoc.customer || refdoc.name);
+ cur_frm.set_value("customer_name", refdoc.customer_name);
+ if(cur_frm.doc.doctype==="Address")
+ cur_frm.set_value("address_title", cur_frm.doc.customer_name);
+ }
}
if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
.indexOf(last_route[1])!==-1) {
@@ -24,7 +32,18 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
cur_frm.set_value("supplier_name", refdoc.supplier_name);
if(cur_frm.doc.doctype==="Address")
- cur_frm.set_value("address_title", cur_frm.doc.supplier)
+ cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
+ }
+ if(["Lead", "Quotation"]
+ .indexOf(last_route[1])!==-1) {
+ var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
+
+ if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) {
+ cur_frm.set_value("lead", refdoc.lead || refdoc.name);
+ cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name);
+ if(cur_frm.doc.doctype==="Address")
+ cur_frm.set_value("address_title", cur_frm.doc.lead_name);
+ }
}
}
}
diff --git a/patches/june_2013/p07_taxes_price_list_for_territory.py b/patches/june_2013/p07_taxes_price_list_for_territory.py
index fbce11557a..9204866718 100644
--- a/patches/june_2013/p07_taxes_price_list_for_territory.py
+++ b/patches/june_2013/p07_taxes_price_list_for_territory.py
@@ -4,11 +4,12 @@ def execute():
webnotes.reload_doc("setup", "doctype", "for_territory")
webnotes.reload_doc("setup", "doctype", "price_list")
webnotes.reload_doc("accounts", "doctype", "sales_taxes_and_charges_master")
+ webnotes.reload_doc("accounts", "doctype", "shipping_rule")
from setup.utils import get_root_of
root_territory = get_root_of("Territory")
- for parenttype in ["Sales Taxes and Charges Master", "Price List"]:
+ for parenttype in ["Sales Taxes and Charges Master", "Price List", "Shipping Rule"]:
for name in webnotes.conn.sql_list("""select name from `tab%s` main
where not exists (select parent from `tabFor Territory` territory
where territory.parenttype=%s and territory.parent=main.name)""" % \
diff --git a/patches/june_2013/p10_lead_address.py b/patches/june_2013/p10_lead_address.py
new file mode 100644
index 0000000000..516e2a68e1
--- /dev/null
+++ b/patches/june_2013/p10_lead_address.py
@@ -0,0 +1,50 @@
+import webnotes
+
+def execute():
+ webnotes.reload_doc("utilities", "doctype", "address")
+
+ webnotes.conn.auto_commit_on_many_writes = True
+
+ for lead in webnotes.conn.sql("""select name as lead, lead_name, address_line1, address_line2, city, country,
+ state, pincode, status, company_name from `tabLead` where not exists
+ (select name from `tabAddress` where `tabAddress`.lead=`tabLead`.name) and
+ (ifnull(address_line1, '')!='' or ifnull(city, '')!='' or ifnull(country, '')!='' or ifnull(pincode, '')!='')""", as_dict=True):
+ if set_in_customer(lead):
+ continue
+
+ create_address_for(lead)
+
+ webnotes.conn.auto_commit_on_many_writes = False
+
+def set_in_customer(lead):
+ customer = webnotes.conn.get_value("Customer", {"lead_name": lead.lead})
+ if customer:
+ customer_address = webnotes.conn.sql("""select name from `tabAddress`
+ where customer=%s and (address_line1=%s or address_line2=%s or pincode=%s)""",
+ (customer, lead.address_line1, lead.address_line2, lead.pincode))
+ if customer_address:
+ webnotes.conn.sql("""update `tabAddress` set lead=%s, lead_name=%s
+ where name=%s""", (lead.lead, lead.company_name or lead.lead_name, customer_address[0][0]))
+ return True
+
+ return False
+
+def create_address_for(lead):
+ address_title = lead.company_name or lead.lead_name or lead.lead
+
+ for c in ['%', "'", '"', '#', '*', '?', '`']:
+ address_title = address_title.replace(c, "")
+
+ if webnotes.conn.get_value("Address", address_title.strip() + "-" + "Billing"):
+ address_title += " " + lead.lead
+
+ lead.update({
+ "doctype": "Address",
+ "address_type": "Billing",
+ "address_title": address_title
+ })
+
+ del lead["company_name"]
+ del lead["status"]
+
+ webnotes.bean(lead).insert()
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 8979f43ea2..aaf5102f64 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -247,5 +247,8 @@ patch_list = [
"patches.june_2013.p06_drop_unused_tables",
"patches.june_2013.p08_shopping_cart_settings",
"patches.june_2013.p05_remove_search_criteria_reports",
+ "patches.june_2013.p07_taxes_price_list_for_territory",
+ "patches.june_2013.p08_shopping_cart_settings",
"patches.june_2013.p09_update_global_defaults",
+ "patches.june_2013.p10_lead_address",
]
\ No newline at end of file
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index 65ac865304..10d2ce52fb 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -62,49 +62,6 @@ class DocType(TransactionBase):
def validate(self):
self.validate_values()
- def create_customer_address(self):
- addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
- address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
-
- if self.doc.phone_1:
- address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
- if self.doc.email_id:
- address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
- webnotes.conn.set(self.doc,'address', address_line)
-
- telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " + "\n" + "(fax): " + cstr(self.doc.fax_1)
- webnotes.conn.set(self.doc,'telephone',telephone)
-
- def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
- c1 = Document('Contact')
- c1.first_name = nm
- c1.contact_name = nm
- c1.contact_no = phn_no
- c1.email_id = email_id
- c1.mobile_no = mob_no
- c1.fax = fax
- c1.contact_address = cont_addr
- c1.is_primary_contact = 'Yes'
- c1.is_customer =1
- c1.customer = self.doc.name
- c1.customer_name = self.doc.customer_name
- c1.customer_address = self.doc.address
- c1.customer_group = self.doc.customer_group
- c1.save(1)
-
- def create_customer_contact(self):
- contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
- contact = contact and contact[0][0] or ''
- if not contact:
- # create primary contact for individual customer
- if self.doc.customer_type == 'Individual':
- self.create_p_contact(self.doc.customer_name,self.doc.phone_1,self.doc.email_id,'',self.doc.fax_1,self.doc.address)
-
- # create primary contact for lead
- elif self.doc.lead_name:
- c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1)
- self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '')
-
def update_lead_status(self):
if self.doc.lead_name:
sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name)
@@ -139,31 +96,16 @@ class DocType(TransactionBase):
def create_lead_address_contact(self):
if self.doc.lead_name:
- details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
- d = Document('Address')
- d.address_line1 = details[0]['address_line1']
- d.address_line2 = details[0]['address_line2']
- d.city = details[0]['city']
- d.country = details[0]['country']
- d.pincode = details[0]['pincode']
- d.state = details[0]['state']
- d.fax = details[0]['fax']
- d.email_id = details[0]['email_id']
- d.phone = details[0]['phone']
- d.customer = self.doc.name
- d.customer_name = self.doc.customer_name
- d.is_primary_address = 1
- d.address_type = 'Office'
- try:
- d.save(1)
- except NameError, e:
- pass
-
+ if not webnotes.conn.get_value("Address", {"lead": self.doc.lead_name, "customer": self.doc.customer}):
+ webnotes.conn.sql("""update `tabAddress` set customer=%s, customer_name=%s where lead=%s""",
+ (self.doc.name, self.doc.customer_name, self.doc.lead_name))
+
+ lead = webnotes.conn.get_value("Lead", self.doc.lead_name, ["lead_name", "email_id", "phone", "mobile_no"], as_dict=True)
c = Document('Contact')
- c.first_name = details[0]['lead_name']
- c.email_id = details[0]['email_id']
- c.phone = details[0]['phone']
- c.mobile_no = details[0]['mobile_no']
+ c.first_name = lead.lead_name
+ c.email_id = lead.email_id
+ c.phone = lead.phone
+ c.mobile_no = lead.mobile_no
c.customer = self.doc.name
c.customer_name = self.doc.customer_name
c.is_primary_contact = 1
diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js
index c94aafa08a..8fb26c5a89 100644
--- a/selling/doctype/lead/lead.js
+++ b/selling/doctype/lead/lead.js
@@ -14,78 +14,79 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-// 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 = '
\
- Sales Email Settings
\
- Automatically extract Leads from a mail box e.g. "sales@example.com"
';
- }
-}
-
-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 = '
\
+ Sales Email Settings
\
+ Automatically extract Leads from a mail box e.g. "sales@example.com"
';
+ }
+ },
+
+ 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;
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py
index a54343a907..928eda7d85 100644
--- a/selling/doctype/lead/lead.py
+++ b/selling/doctype/lead/lead.py
@@ -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')
diff --git a/selling/doctype/lead/lead.txt b/selling/doctype/lead/lead.txt
index 0b602ea7e1..eed87ba399 100644
--- a/selling/doctype/lead/lead.txt
+++ b/selling/doctype/lead/lead.txt
@@ -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": "Addresses will appear only when you save the lead",
+ "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",
diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt
index 74a4396aef..b9772c8379 100644
--- a/selling/doctype/quotation/quotation.txt
+++ b/selling/doctype/quotation/quotation.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:08",
"docstatus": 0,
- "modified": "2013-06-19 15:55:15",
+ "modified": "2013-06-28 12:47:10",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -420,7 +420,7 @@
"fieldname": "charge",
"fieldtype": "Link",
"hidden": 0,
- "label": "Sales Taxes and Charges",
+ "label": "Apply Taxes and Charges Master",
"oldfieldname": "charge",
"oldfieldtype": "Link",
"options": "Sales Taxes and Charges Master",
@@ -434,11 +434,12 @@
},
{
"doctype": "DocField",
- "fieldname": "get_charges",
- "fieldtype": "Button",
+ "fieldname": "shipping_rule",
+ "fieldtype": "Link",
"hidden": 0,
- "label": "Get Taxes and Charges",
+ "label": "Apply Shipping Rule",
"oldfieldtype": "Button",
+ "options": "Shipping Rule",
"print_hide": 1,
"read_only": 0
},
@@ -689,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",
diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js
index 2d30601f26..77e77592e9 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -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() {
@@ -368,7 +371,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
},
- get_charges: function() {
+ charge: function() {
var me = this;
if(this.frm.doc.charge) {
this.frm.call({
@@ -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
diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js
index d8aab21fbd..d9e2d7b047 100644
--- a/selling/doctype/sales_order/sales_order.js
+++ b/selling/doctype/sales_order/sales_order.js
@@ -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];
diff --git a/selling/doctype/sales_order/sales_order.txt b/selling/doctype/sales_order/sales_order.txt
index dcb0306beb..6bb1d265f6 100644
--- a/selling/doctype/sales_order/sales_order.txt
+++ b/selling/doctype/sales_order/sales_order.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-06-18 12:39:59",
"docstatus": 0,
- "modified": "2013-06-18 17:49:11",
+ "modified": "2013-06-27 11:31:02",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -450,7 +450,7 @@
"doctype": "DocField",
"fieldname": "charge",
"fieldtype": "Link",
- "label": "Sales Taxes and Charges",
+ "label": "Apply Taxes and Charges Master",
"oldfieldname": "charge",
"oldfieldtype": "Link",
"options": "Sales Taxes and Charges Master",
@@ -463,10 +463,12 @@
},
{
"doctype": "DocField",
- "fieldname": "get_charges",
- "fieldtype": "Button",
- "label": "Get Taxes and Charges",
- "oldfieldtype": "Button"
+ "fieldname": "shipping_rule",
+ "fieldtype": "Link",
+ "label": "Apply Shipping Rule",
+ "oldfieldtype": "Button",
+ "options": "Shipping Rule",
+ "print_hide": 1
},
{
"doctype": "DocField",
diff --git a/setup/doctype/contact_control/contact_control.js b/setup/doctype/contact_control/contact_control.js
index 79e9de70da..c427ec09fd 100755
--- a/setup/doctype/contact_control/contact_control.js
+++ b/setup/doctype/contact_control/contact_control.js
@@ -59,8 +59,8 @@ cur_frm.cscript.render_address_row = function(wrapper, data) {
// prepare data
data.fullname = data.address_type;
data.primary = '';
- if (data.is_primary_address) data.primary += ' [Primary]';
- if (data.is_shipping_address) data.primary += ' [Shipping]';
+ if (data.is_primary_address) data.primary += ' [Preferred for Billing]';
+ if (data.is_shipping_address) data.primary += ' [Preferred for Shipping]';
// prepare address
var address = [];
diff --git a/stock/doctype/delivery_note/delivery_note.txt b/stock/doctype/delivery_note/delivery_note.txt
index 74a21b3a14..20e2196cb0 100644
--- a/stock/doctype/delivery_note/delivery_note.txt
+++ b/stock/doctype/delivery_note/delivery_note.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:09",
"docstatus": 0,
- "modified": "2013-06-05 19:22:52",
+ "modified": "2013-06-27 11:33:53",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -449,7 +449,7 @@
"doctype": "DocField",
"fieldname": "charge",
"fieldtype": "Link",
- "label": "Taxes and Charges",
+ "label": "Apply Taxes and Charges Master",
"oldfieldname": "charge",
"oldfieldtype": "Link",
"options": "Sales Taxes and Charges Master",
@@ -463,10 +463,11 @@
},
{
"doctype": "DocField",
- "fieldname": "get_charges",
- "fieldtype": "Button",
- "label": "Get Taxes and Charges",
+ "fieldname": "shipping_rule",
+ "fieldtype": "Link",
+ "label": "Apply Shipping Rule",
"oldfieldtype": "Button",
+ "options": "Shipping Rule",
"print_hide": 1,
"read_only": 0
},
diff --git a/support/doctype/newsletter/newsletter.py b/support/doctype/newsletter/newsletter.py
index 78921f176f..e654470998 100644
--- a/support/doctype/newsletter/newsletter.py
+++ b/support/doctype/newsletter/newsletter.py
@@ -19,7 +19,6 @@ from __future__ import unicode_literals
import webnotes
import webnotes.utils
from webnotes.utils import cstr
-from webnotes.model.doc import Document
from webnotes import _
class DocType():
@@ -73,8 +72,7 @@ class DocType():
elif self.doc.email_list:
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
for email in email_list:
- if not webnotes.conn.exists({"doctype": "Lead", "email_id": email}):
- create_lead(email)
+ create_lead(email)
self.send_to_doctype = "Lead"
return email_list
@@ -116,15 +114,20 @@ def create_lead(email_id):
"""create a lead if it does not exist"""
from email.utils import parseaddr
real_name, email_id = parseaddr(email_id)
- lead = Document("Lead")
- lead.fields["__islocal"] = 1
- lead.lead_name = real_name or email_id
- lead.email_id = email_id
- lead.status = "Contacted"
- lead.naming_series = lead_naming_series or get_lead_naming_series()
- lead.company = webnotes.conn.get_default("company")
- lead.source = "Email"
- lead.save()
+
+ if webnotes.conn.get_value("Lead", {"email_id": email_id}):
+ return
+
+ lead = webnotes.bean({
+ "doctype": "Lead",
+ "email_id": email_id,
+ "lead_name": real_name or email_id,
+ "status": "Contacted",
+ "naming_series": lead_naming_series or get_lead_naming_series(),
+ "company": webnotes.conn.get_default("company"),
+ "source": "Email"
+ })
+ lead.insert()
def get_lead_naming_series():
"""gets lead's default naming series"""
diff --git a/utilities/doctype/address/address.py b/utilities/doctype/address/address.py
index cfcbea582f..c475da12b5 100644
--- a/utilities/doctype/address/address.py
+++ b/utilities/doctype/address/address.py
@@ -27,7 +27,7 @@ class DocType:
def autoname(self):
if not self.doc.address_title:
- self.doc.address_title = self.doc.customer or self.doc.supplier or self.doc.sales_partner
+ self.doc.address_title = self.doc.customer or self.doc.supplier or self.doc.sales_partner or self.doc.lead
if self.doc.address_title:
self.doc.name = cstr(self.doc.address_title).strip() + "-" + cstr(self.doc.address_type).strip()
@@ -35,40 +35,32 @@ class DocType:
else:
webnotes.msgprint("""Address Title is mandatory.""", raise_exception=True)
-
def validate(self):
self.validate_primary_address()
self.validate_shipping_address()
def validate_primary_address(self):
"""Validate that there can only be one primary address for particular customer, supplier"""
- sql = webnotes.conn.sql
if self.doc.is_primary_address == 1:
- if self.doc.customer:
- sql("update tabAddress set is_primary_address=0 where customer = '%s'" % (self.doc.customer))
- elif self.doc.supplier:
- sql("update tabAddress set is_primary_address=0 where supplier = '%s'" % (self.doc.supplier))
- elif self.doc.sales_partner:
- sql("update tabAddress set is_primary_address=0 where sales_partner = '%s'" % (self.doc.sales_partner))
- elif not self.doc.is_shipping_address:
- if self.doc.customer:
- if not sql("select name from tabAddress where is_primary_address=1 and customer = '%s'" % (self.doc.customer)):
- self.doc.is_primary_address = 1
- elif self.doc.supplier:
- if not sql("select name from tabAddress where is_primary_address=1 and supplier = '%s'" % (self.doc.supplier)):
- self.doc.is_primary_address = 1
- elif self.doc.sales_partner:
- if not sql("select name from tabAddress where is_primary_address=1 and sales_partner = '%s'" % (self.doc.sales_partner)):
- self.doc.is_primary_address = 1
-
+ self._unset_other("is_primary_address")
+
+ elif self.doc.is_shipping_address != 1:
+ for fieldname in ["customer", "supplier", "sales_partner", "lead"]:
+ if self.doc.fields.get(fieldname):
+ if not webnotes.conn.sql("""select name from `tabAddress` where is_primary_address=1
+ and `%s`=%s and name!=%s""" % (fieldname, "%s", "%s"),
+ (self.doc.fields[fieldname], self.doc.name)):
+ self.doc.is_primary_address = 1
+ break
def validate_shipping_address(self):
"""Validate that there can only be one shipping address for particular customer, supplier"""
- sql = webnotes.conn.sql
if self.doc.is_shipping_address == 1:
- if self.doc.customer:
- sql("update tabAddress set is_shipping_address=0 where customer = '%s'" % (self.doc.customer))
- elif self.doc.supplier:
- sql("update tabAddress set is_shipping_address=0 where supplier = '%s'" % (self.doc.supplier))
- elif self.doc.sales_partner:
- sql("update tabAddress set is_shipping_address=0 where sales_partner = '%s'" % (self.doc.sales_partner))
+ self._unset_other("is_shipping_address")
+
+ def _unset_other(self, is_address_type):
+ for fieldname in ["customer", "supplier", "sales_partner", "lead"]:
+ if self.doc.fields.get(fieldname):
+ webnotes.conn.sql("""update `tabAddress` set `%s`=0 where `%s`=%s and name!=%s""" %
+ (is_address_type, fieldname, "%s", "%s"), (self.doc.fields[fieldname], self.doc.name))
+ break
\ No newline at end of file
diff --git a/utilities/doctype/address/address.txt b/utilities/doctype/address/address.txt
index 757beb9656..ed39c759c5 100644
--- a/utilities/doctype/address/address.txt
+++ b/utilities/doctype/address/address.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-01-10 16:34:32",
"docstatus": 0,
- "modified": "2013-01-29 13:24:45",
+ "modified": "2013-06-28 17:06:32",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -46,11 +46,11 @@
"label": "Address Details"
},
{
- "description": "e.g. Office, Billing, Shipping",
"doctype": "DocField",
"fieldname": "address_type",
- "fieldtype": "Data",
+ "fieldtype": "Select",
"label": "Address Type",
+ "options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther",
"reqd": 1
},
{
@@ -145,7 +145,7 @@
"doctype": "DocField",
"fieldname": "is_primary_address",
"fieldtype": "Check",
- "label": "Is Primary Address"
+ "label": "Preferred Billing Address"
},
{
"default": "0",
@@ -154,7 +154,7 @@
"fieldname": "is_shipping_address",
"fieldtype": "Check",
"in_list_view": 1,
- "label": "Is Shipping Address"
+ "label": "Preferred Shipping Address"
},
{
"doctype": "DocField",
@@ -207,6 +207,27 @@
"label": "Sales Partner",
"options": "Sales Partner"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "column_break_22",
+ "fieldtype": "Column Break"
+ },
+ {
+ "depends_on": "eval:!doc.supplier && !doc.sales_partner",
+ "doctype": "DocField",
+ "fieldname": "lead",
+ "fieldtype": "Link",
+ "label": "Lead",
+ "options": "Lead"
+ },
+ {
+ "depends_on": "eval:!doc.supplier && !doc.sales_partner",
+ "doctype": "DocField",
+ "fieldname": "lead_name",
+ "fieldtype": "Data",
+ "label": "Lead Name",
+ "read_only": 1
+ },
{
"doctype": "DocPerm",
"role": "Sales User"
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index c86a50ec19..2def0ea05f 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -170,21 +170,30 @@ class TransactionBase(StatusUpdater):
# Get Lead Details
# -----------------------
- def get_lead_details(self, name):
- details = webnotes.conn.sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, territory, phone, mobile_no, email_id, company_name from `tabLead` where name = '%s'" %(name), as_dict = 1)
-
- extract = lambda x: details and details[0] and details[0].get(x,'') or ''
- address_fields = [('','address_line1'),('\n','address_line2'),('\n','city'),(' ','pincode'),('\n','state'),('\n','country'),('\nPhone: ','contact_no')]
- address_display = ''.join([a[0]+extract(a[1]) for a in address_fields if extract(a[1])])
- if address_display.startswith('\n'): address_display = address_display[1:]
+ def get_lead_details(self, name):
+ details = webnotes.conn.sql("""select name, lead_name, address_line1, address_line2, city, country, state, pincode
+ from `tabAddress` where lead=%s""", name, as_dict=True)
+ lead = webnotes.conn.get_value("Lead", name,
+ ["territory", "phone", "mobile_no", "email_id", "company_name", "lead_name"], as_dict=True) or {}
+
+ address_display = ""
+ if details:
+ details = details[0]
+ for separator, fieldname in (('','address_line1'), ('\n','address_line2'), ('\n','city'),
+ (' ','pincode'), ('\n','state'), ('\n','country'), ('\nPhone: ', 'phone')):
+ if details.get(fieldname):
+ address_display += separator + details.get(fieldname)
+
+ if address_display.startswith('\n'):
+ address_display = address_display[1:]
ret = {
- 'contact_display' : extract('lead_name'),
+ 'contact_display' : lead.get('lead_name'),
'address_display' : address_display,
- 'territory' : extract('territory'),
- 'contact_mobile' : extract('mobile_no'),
- 'contact_email' : extract('email_id'),
- 'customer_name' : extract('company_name') or extract('lead_name')
+ 'territory' : lead.get('territory'),
+ 'contact_mobile' : lead.get('mobile_no'),
+ 'contact_email' : lead.get('email_id'),
+ 'customer_name' : lead.get('company_name') or lead.get('lead_name')
}
return ret