[fix] delete lead addresses in delete company transaction
This commit is contained in:
parent
bdd1ee2185
commit
8ee5498fe0
@ -17,16 +17,16 @@ def delete_company_transactions(company_name):
|
|||||||
frappe.throw(_("Transactions can only be deleted by the creator of the Company"), frappe.PermissionError)
|
frappe.throw(_("Transactions can only be deleted by the creator of the Company"), frappe.PermissionError)
|
||||||
|
|
||||||
delete_bins(company_name)
|
delete_bins(company_name)
|
||||||
|
|
||||||
delete_time_logs(company_name)
|
delete_time_logs(company_name)
|
||||||
|
delete_lead_addresses(company_name)
|
||||||
|
|
||||||
for doctype in frappe.db.sql_list("""select parent from
|
for doctype in frappe.db.sql_list("""select parent from
|
||||||
tabDocField where fieldtype='Link' and options='Company'"""):
|
tabDocField where fieldtype='Link' and options='Company'"""):
|
||||||
if doctype not in ("Account", "Cost Center", "Warehouse", "Budget Detail",
|
if doctype not in ("Account", "Cost Center", "Warehouse", "Budget Detail",
|
||||||
"Party Account", "Employee", "Sales Taxes and Charges Template",
|
"Party Account", "Employee", "Sales Taxes and Charges Template",
|
||||||
"Purchase Taxes and Charges Template", "POS Profile"):
|
"Purchase Taxes and Charges Template", "POS Profile"):
|
||||||
delete_for_doctype(doctype, company_name)
|
delete_for_doctype(doctype, company_name)
|
||||||
|
|
||||||
# Clear notification counts
|
# Clear notification counts
|
||||||
clear_notifications()
|
clear_notifications()
|
||||||
|
|
||||||
@ -73,15 +73,22 @@ def delete_time_logs(company_name):
|
|||||||
# Delete Time Logs as it is linked to Production Order / Project / Task, which are linked to company
|
# Delete Time Logs as it is linked to Production Order / Project / Task, which are linked to company
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
delete from `tabTime Log`
|
delete from `tabTime Log`
|
||||||
where
|
where
|
||||||
(ifnull(project, '') != ''
|
(ifnull(project, '') != ''
|
||||||
and exists(select name from `tabProject` where name=`tabTime Log`.project and company=%(company)s))
|
and exists(select name from `tabProject` where name=`tabTime Log`.project and company=%(company)s))
|
||||||
or (ifnull(task, '') != ''
|
or (ifnull(task, '') != ''
|
||||||
and exists(select name from `tabTask` where name=`tabTime Log`.task and company=%(company)s))
|
and exists(select name from `tabTask` where name=`tabTime Log`.task and company=%(company)s))
|
||||||
or (ifnull(production_order, '') != ''
|
or (ifnull(production_order, '') != ''
|
||||||
and exists(select name from `tabProduction Order`
|
and exists(select name from `tabProduction Order`
|
||||||
where name=`tabTime Log`.production_order and company=%(company)s))
|
where name=`tabTime Log`.production_order and company=%(company)s))
|
||||||
or (ifnull(sales_invoice, '') != ''
|
or (ifnull(sales_invoice, '') != ''
|
||||||
and exists(select name from `tabSales Invoice`
|
and exists(select name from `tabSales Invoice`
|
||||||
where name=`tabTime Log`.sales_invoice and company=%(company)s))
|
where name=`tabTime Log`.sales_invoice and company=%(company)s))
|
||||||
""", {"company": company_name})
|
""", {"company": company_name})
|
||||||
|
|
||||||
|
def delete_lead_addresses(company_name):
|
||||||
|
"""Delete addresses to which leads are linked"""
|
||||||
|
frappe.db.sql("""delete from `tabAddress`
|
||||||
|
where (customer='' or customer is null) and (supplier='' or supplier is null) and (lead != '' and lead is not null)""")
|
||||||
|
|
||||||
|
frappe.db.sql("""update `tabAddress` set lead=null, lead_name=null""")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user