mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-06 06:58:27 +00:00
[lead] [address] store lead address in Address doctype, with link field=lead
This commit is contained in:
@@ -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)""" % \
|
||||
|
||||
50
patches/june_2013/p10_lead_address.py
Normal file
50
patches/june_2013/p10_lead_address.py
Normal file
@@ -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()
|
||||
@@ -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",
|
||||
]
|
||||
Reference in New Issue
Block a user