[fixes] delete company transaction and other minor fixes
This commit is contained in:
parent
83f4780f74
commit
7fa039f15c
@ -73,11 +73,17 @@ def delete_bins(company_name):
|
|||||||
|
|
||||||
def delete_lead_addresses(company_name):
|
def delete_lead_addresses(company_name):
|
||||||
"""Delete addresses to which leads are linked"""
|
"""Delete addresses to which leads are linked"""
|
||||||
for lead in frappe.get_all("Lead", filters={"company": company_name}):
|
leads = frappe.get_all("Lead", filters={"company": company_name})
|
||||||
frappe.db.sql("""delete from `tabAddress`
|
leads = [ "'%s'"%row.get("name") for row in leads ]
|
||||||
where lead=%s and (customer='' or customer is null) and (supplier='' or supplier is null)""", lead.name)
|
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):
|
def delete_communications(doctype, company_name, company_fieldname):
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
|
@ -8,9 +8,12 @@ def load_address_and_contact(doc, key):
|
|||||||
"""Loads address list and contact list in `__onload`"""
|
"""Loads address list and contact list in `__onload`"""
|
||||||
from frappe.geo.doctype.address.address import get_address_display
|
from frappe.geo.doctype.address.address import get_address_display
|
||||||
|
|
||||||
address_list = [frappe.get_value('Address', a.parent, '*')
|
filters = [
|
||||||
for a in frappe.get_all('Dynamic Link', fields='parent',
|
["Dynamic Link", "link_doctype", "=", doc.doctype],
|
||||||
filters=dict(parenttype='Address', link_doctype=doc.doctype, link_name=doc.name))]
|
["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)})
|
address_list = [a.update({"display": get_address_display(a)})
|
||||||
for a in address_list]
|
for a in address_list]
|
||||||
@ -23,9 +26,12 @@ def load_address_and_contact(doc, key):
|
|||||||
doc.set_onload('addr_list', address_list)
|
doc.set_onload('addr_list', address_list)
|
||||||
|
|
||||||
if doc.doctype != "Lead":
|
if doc.doctype != "Lead":
|
||||||
contact_list = [frappe.get_value('Contact', a.parent, '*')
|
filters = [
|
||||||
for a in frappe.get_all('Dynamic Link', fields='parent',
|
["Dynamic Link", "link_doctype", "=", doc.doctype],
|
||||||
filters=dict(parenttype='Contact', link_doctype=doc.doctype, link_name=doc.name))]
|
["Dynamic Link", "link_name", "=", doc.name],
|
||||||
|
["Dynamic Link", "parenttype", "=", "Contact"],
|
||||||
|
]
|
||||||
|
contact_list = frappe.get_all("Contact", filters=filters, fields=["*"])
|
||||||
|
|
||||||
contact_list = sorted(contact_list,
|
contact_list = sorted(contact_list,
|
||||||
lambda a, b:
|
lambda a, b:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user