[fixes] delete company transaction and other minor fixes

This commit is contained in:
mbauskar 2017-01-23 11:27:47 +05:30
parent 83f4780f74
commit 7fa039f15c
2 changed files with 22 additions and 10 deletions

View File

@ -73,11 +73,17 @@ def delete_bins(company_name):
def delete_lead_addresses(company_name):
"""Delete addresses to which leads are linked"""
for lead in frappe.get_all("Lead", filters={"company": company_name}):
frappe.db.sql("""delete from `tabAddress`
where lead=%s and (customer='' or customer is null) and (supplier='' or supplier is null)""", lead.name)
leads = frappe.get_all("Lead", filters={"company": company_name})
leads = [ "'%s'"%row.get("name") for row in leads ]
if leads:
frappe.db.sql("""delete from tabAddress where name not in (select parent
from `tabDynamic Link` dl where dl.link_doctype<>'Lead' and
dl.parenttype='Address')""", debug=True)
frappe.db.sql("""update `tabAddress` set lead=null, lead_name=null where lead=%s""", lead.name)
frappe.db.sql("""delete from `tabDynamic Link` where link_doctype='Lead' and parenttype='Address'
and link_name in ({leads})""".format(leads=",".join(leads)), debug=True)
frappe.db.sql("""update tabCustomer set lead_name='' where lead_name in ({leads})""".format(leads=",".join(leads)), debug=True)
def delete_communications(doctype, company_name, company_fieldname):
frappe.db.sql("""

View File

@ -8,9 +8,12 @@ def load_address_and_contact(doc, key):
"""Loads address list and contact list in `__onload`"""
from frappe.geo.doctype.address.address import get_address_display
address_list = [frappe.get_value('Address', a.parent, '*')
for a in frappe.get_all('Dynamic Link', fields='parent',
filters=dict(parenttype='Address', link_doctype=doc.doctype, link_name=doc.name))]
filters = [
["Dynamic Link", "link_doctype", "=", doc.doctype],
["Dynamic Link", "link_name", "=", doc.name],
["Dynamic Link", "parenttype", "=", "Address"],
]
address_list = frappe.get_all("Address", filters=filters, fields=["*"])
address_list = [a.update({"display": get_address_display(a)})
for a in address_list]
@ -23,9 +26,12 @@ def load_address_and_contact(doc, key):
doc.set_onload('addr_list', address_list)
if doc.doctype != "Lead":
contact_list = [frappe.get_value('Contact', a.parent, '*')
for a in frappe.get_all('Dynamic Link', fields='parent',
filters=dict(parenttype='Contact', link_doctype=doc.doctype, link_name=doc.name))]
filters = [
["Dynamic Link", "link_doctype", "=", doc.doctype],
["Dynamic Link", "link_name", "=", doc.name],
["Dynamic Link", "parenttype", "=", "Contact"],
]
contact_list = frappe.get_all("Contact", filters=filters, fields=["*"])
contact_list = sorted(contact_list,
lambda a, b: