mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-17 02:26:33 +00:00
Changed frappe.conn to frappe.db
This commit is contained in:
@@ -22,18 +22,18 @@ class DocType(TransactionBase):
|
||||
raise_exception=True)
|
||||
|
||||
if self.doc.status=="Closed" and \
|
||||
frappe.conn.get_value("Customer Issue", self.doc.name, "status")!="Closed":
|
||||
frappe.db.get_value("Customer Issue", self.doc.name, "status")!="Closed":
|
||||
self.doc.resolution_date = today()
|
||||
self.doc.resolved_by = frappe.session.user
|
||||
|
||||
def on_cancel(self):
|
||||
lst = frappe.conn.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t2.prevdoc_docname = '%s' and t1.docstatus!=2"%(self.doc.name))
|
||||
lst = frappe.db.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t2.prevdoc_docname = '%s' and t1.docstatus!=2"%(self.doc.name))
|
||||
if lst:
|
||||
lst1 = ','.join([x[0] for x in lst])
|
||||
msgprint("Maintenance Visit No. "+lst1+" already created against this customer issue. So can not be Cancelled")
|
||||
raise Exception
|
||||
else:
|
||||
frappe.conn.set(self.doc, 'status', 'Cancelled')
|
||||
frappe.db.set(self.doc, 'status', 'Cancelled')
|
||||
|
||||
def on_update(self):
|
||||
pass
|
||||
@@ -42,7 +42,7 @@ class DocType(TransactionBase):
|
||||
def make_maintenance_visit(source_name, target_doclist=None):
|
||||
from frappe.model.mapper import get_mapped_doclist
|
||||
|
||||
visit = frappe.conn.sql("""select t1.name
|
||||
visit = frappe.db.sql("""select t1.name
|
||||
from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2
|
||||
where t2.parent=t1.name and t2.prevdoc_docname=%s
|
||||
and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name)
|
||||
|
||||
@@ -16,7 +16,7 @@ class DocType(TransactionBase):
|
||||
self.doclist = doclist
|
||||
|
||||
def get_item_details(self, item_code):
|
||||
item = frappe.conn.sql("""select item_name, description from `tabItem`
|
||||
item = frappe.db.sql("""select item_name, description from `tabItem`
|
||||
where name=%s""", (item_code), as_dict=1)
|
||||
ret = {
|
||||
'item_name': item and item[0]['item_name'] or '',
|
||||
@@ -26,7 +26,7 @@ class DocType(TransactionBase):
|
||||
|
||||
def generate_schedule(self):
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
|
||||
frappe.conn.sql("""delete from `tabMaintenance Schedule Detail`
|
||||
frappe.db.sql("""delete from `tabMaintenance Schedule Detail`
|
||||
where parent=%s""", (self.doc.name))
|
||||
count = 1
|
||||
for d in getlist(self.doclist, 'item_maintenance_detail'):
|
||||
@@ -64,7 +64,7 @@ class DocType(TransactionBase):
|
||||
sp = frappe.bean("Sales Person", d.sales_person).make_controller()
|
||||
email_map[d.sales_person] = sp.get_email_id()
|
||||
|
||||
scheduled_date = frappe.conn.sql("""select scheduled_date from
|
||||
scheduled_date = frappe.db.sql("""select scheduled_date from
|
||||
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
||||
parent=%s""", (d.sales_person, d.item_code, self.doc.name), as_dict=1)
|
||||
|
||||
@@ -83,7 +83,7 @@ class DocType(TransactionBase):
|
||||
"ref_name": self.doc.name
|
||||
}).insert()
|
||||
|
||||
frappe.conn.set(self.doc, 'status', 'Submitted')
|
||||
frappe.db.set(self.doc, 'status', 'Submitted')
|
||||
|
||||
#get schedule dates
|
||||
#----------------------
|
||||
@@ -117,7 +117,7 @@ class DocType(TransactionBase):
|
||||
|
||||
if fy_details and fy_details[0]:
|
||||
# check holiday list in employee master
|
||||
holiday_list = frappe.conn.sql_list("""select h.holiday_date from `tabEmployee` emp,
|
||||
holiday_list = frappe.db.sql_list("""select h.holiday_date from `tabEmployee` emp,
|
||||
`tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl
|
||||
where sp.name=%s and emp.name=sp.employee
|
||||
and hl.name=emp.holiday_list and
|
||||
@@ -125,7 +125,7 @@ class DocType(TransactionBase):
|
||||
hl.fiscal_year=%s""", (sales_person, fy_details[0]))
|
||||
if not holiday_list:
|
||||
# check global holiday list
|
||||
holiday_list = frappe.conn.sql("""select h.holiday_date from
|
||||
holiday_list = frappe.db.sql("""select h.holiday_date from
|
||||
`tabHoliday` h, `tabHoliday List` hl
|
||||
where h.parent=hl.name and ifnull(hl.is_default, 0) = 1
|
||||
and hl.fiscal_year=%s""", fy_details[0])
|
||||
@@ -197,7 +197,7 @@ class DocType(TransactionBase):
|
||||
def validate_sales_order(self):
|
||||
for d in getlist(self.doclist, 'item_maintenance_detail'):
|
||||
if d.prevdoc_docname:
|
||||
chk = frappe.conn.sql("""select ms.name from `tabMaintenance Schedule` ms,
|
||||
chk = frappe.db.sql("""select ms.name from `tabMaintenance Schedule` ms,
|
||||
`tabMaintenance Schedule Item` msi where msi.parent=ms.name and
|
||||
msi.prevdoc_docname=%s and ms.docstatus=1""", d.prevdoc_docname)
|
||||
if chk:
|
||||
@@ -212,7 +212,7 @@ class DocType(TransactionBase):
|
||||
cur_s_no = cur_serial_no.split(',')
|
||||
|
||||
for x in cur_s_no:
|
||||
chk = frappe.conn.sql("""select name, status from `tabSerial No`
|
||||
chk = frappe.db.sql("""select name, status from `tabSerial No`
|
||||
where docstatus!=2 and name=%s""", (x))
|
||||
chk1 = chk and chk[0][0] or ''
|
||||
status = chk and chk[0][1] or ''
|
||||
@@ -235,7 +235,7 @@ class DocType(TransactionBase):
|
||||
cur_s_no = cur_serial_no.split(',')
|
||||
|
||||
for x in cur_s_no:
|
||||
dt = frappe.conn.sql("""select delivery_date from `tabSerial No`
|
||||
dt = frappe.db.sql("""select delivery_date from `tabSerial No`
|
||||
where name=%s""", x)
|
||||
dt = dt and dt[0][0] or ''
|
||||
|
||||
@@ -251,16 +251,16 @@ class DocType(TransactionBase):
|
||||
cur_s_no = cur_serial_no.split(',')
|
||||
|
||||
for x in cur_s_no:
|
||||
frappe.conn.sql("""update `tabSerial No` set amc_expiry_date=%s,
|
||||
frappe.db.sql("""update `tabSerial No` set amc_expiry_date=%s,
|
||||
maintenance_status='Under AMC' where name=%s""", (amc_end_date, x))
|
||||
|
||||
def on_update(self):
|
||||
frappe.conn.set(self.doc, 'status', 'Draft')
|
||||
frappe.db.set(self.doc, 'status', 'Draft')
|
||||
|
||||
def validate_serial_no_warranty(self):
|
||||
for d in getlist(self.doclist, 'item_maintenance_detail'):
|
||||
if cstr(d.serial_no).strip():
|
||||
dt = frappe.conn.sql("""select warranty_expiry_date, amc_expiry_date
|
||||
dt = frappe.db.sql("""select warranty_expiry_date, amc_expiry_date
|
||||
from `tabSerial No` where name=%s""", d.serial_no, as_dict=1)
|
||||
if dt[0]['warranty_expiry_date'] and dt[0]['warranty_expiry_date'] >= d.start_date:
|
||||
throw("""Serial No: %s is already under warranty upto %s.
|
||||
@@ -307,7 +307,7 @@ class DocType(TransactionBase):
|
||||
for d in getlist(self.doclist, 'item_maintenance_detail'):
|
||||
if d.serial_no:
|
||||
self.update_amc_date(d.serial_no, '')
|
||||
frappe.conn.set(self.doc, 'status', 'Cancelled')
|
||||
frappe.db.set(self.doc, 'status', 'Cancelled')
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
|
||||
def on_trash(self):
|
||||
|
||||
@@ -18,7 +18,7 @@ class DocType(TransactionBase):
|
||||
self.doclist = doclist
|
||||
|
||||
def get_item_details(self, item_code):
|
||||
item = frappe.conn.sql("select item_name,description from `tabItem` where name = '%s'" %(item_code), as_dict=1)
|
||||
item = frappe.db.sql("select item_name,description from `tabItem` where name = '%s'" %(item_code), as_dict=1)
|
||||
ret = {
|
||||
'item_name' : item and item[0]['item_name'] or '',
|
||||
'description' : item and item[0]['description'] or ''
|
||||
@@ -27,7 +27,7 @@ class DocType(TransactionBase):
|
||||
|
||||
def validate_serial_no(self):
|
||||
for d in getlist(self.doclist, 'maintenance_visit_details'):
|
||||
if d.serial_no and not frappe.conn.sql("select name from `tabSerial No` where name = '%s' and docstatus != 2" % d.serial_no):
|
||||
if d.serial_no and not frappe.db.sql("select name from `tabSerial No` where name = '%s' and docstatus != 2" % d.serial_no):
|
||||
msgprint("Serial No: "+ d.serial_no + " not exists in the system")
|
||||
raise Exception
|
||||
|
||||
@@ -51,7 +51,7 @@ class DocType(TransactionBase):
|
||||
elif self.doc.completion_status == 'Partially Completed':
|
||||
status = 'Work In Progress'
|
||||
else:
|
||||
nm = frappe.conn.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.doc.name))
|
||||
nm = frappe.db.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.doc.name))
|
||||
|
||||
if nm:
|
||||
status = 'Work In Progress'
|
||||
@@ -64,7 +64,7 @@ class DocType(TransactionBase):
|
||||
service_person = ''
|
||||
work_done = ''
|
||||
|
||||
frappe.conn.sql("update `tabCustomer Issue` set resolution_date=%s, resolved_by=%s, resolution_details=%s, status=%s where name =%s",(mntc_date,service_person,work_done,status,d.prevdoc_docname))
|
||||
frappe.db.sql("update `tabCustomer Issue` set resolution_date=%s, resolved_by=%s, resolution_details=%s, status=%s where name =%s",(mntc_date,service_person,work_done,status,d.prevdoc_docname))
|
||||
|
||||
|
||||
def check_if_last_visit(self):
|
||||
@@ -76,7 +76,7 @@ class DocType(TransactionBase):
|
||||
check_for_doctype = d.prevdoc_doctype
|
||||
|
||||
if check_for_docname:
|
||||
check = frappe.conn.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.name!=%s and t2.prevdoc_docname=%s and t1.docstatus = 1 and (t1.mntc_date > %s or (t1.mntc_date = %s and t1.mntc_time > %s))", (self.doc.name, check_for_docname, self.doc.mntc_date, self.doc.mntc_date, self.doc.mntc_time))
|
||||
check = frappe.db.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.name!=%s and t2.prevdoc_docname=%s and t1.docstatus = 1 and (t1.mntc_date > %s or (t1.mntc_date = %s and t1.mntc_time > %s))", (self.doc.name, check_for_docname, self.doc.mntc_date, self.doc.mntc_date, self.doc.mntc_time))
|
||||
|
||||
if check:
|
||||
check_lst = [x[0] for x in check]
|
||||
@@ -88,11 +88,11 @@ class DocType(TransactionBase):
|
||||
|
||||
def on_submit(self):
|
||||
self.update_customer_issue(1)
|
||||
frappe.conn.set(self.doc, 'status', 'Submitted')
|
||||
frappe.db.set(self.doc, 'status', 'Submitted')
|
||||
|
||||
def on_cancel(self):
|
||||
self.check_if_last_visit()
|
||||
frappe.conn.set(self.doc, 'status', 'Cancelled')
|
||||
frappe.db.set(self.doc, 'status', 'Cancelled')
|
||||
|
||||
def on_update(self):
|
||||
pass
|
||||
@@ -14,7 +14,7 @@ class DocType():
|
||||
|
||||
def onload(self):
|
||||
if self.doc.email_sent:
|
||||
self.doc.fields["__status_count"] = dict(frappe.conn.sql("""select status, count(*)
|
||||
self.doc.fields["__status_count"] = dict(frappe.db.sql("""select status, count(*)
|
||||
from `tabBulk Email` where ref_doctype=%s and ref_docname=%s
|
||||
group by status""", (self.doc.doctype, self.doc.name))) or None
|
||||
|
||||
@@ -41,18 +41,18 @@ class DocType():
|
||||
"doctype": self.send_to_doctype
|
||||
}))
|
||||
|
||||
frappe.conn.set(self.doc, "email_sent", 1)
|
||||
frappe.db.set(self.doc, "email_sent", 1)
|
||||
|
||||
def get_recipients(self):
|
||||
self.email_field = None
|
||||
if self.doc.send_to_type=="Contact":
|
||||
self.send_to_doctype = "Contact"
|
||||
if self.doc.contact_type == "Customer":
|
||||
return frappe.conn.sql_list("""select email_id from tabContact
|
||||
return frappe.db.sql_list("""select email_id from tabContact
|
||||
where ifnull(email_id, '') != '' and ifnull(customer, '') != ''""")
|
||||
|
||||
elif self.doc.contact_type == "Supplier":
|
||||
return frappe.conn.sql_list("""select email_id from tabContact
|
||||
return frappe.db.sql_list("""select email_id from tabContact
|
||||
where ifnull(email_id, '') != '' and ifnull(supplier, '') != ''""")
|
||||
|
||||
elif self.doc.send_to_type=="Lead":
|
||||
@@ -66,14 +66,14 @@ class DocType():
|
||||
if conditions:
|
||||
conditions = "".join(conditions)
|
||||
|
||||
return frappe.conn.sql_list("""select email_id from tabLead
|
||||
return frappe.db.sql_list("""select email_id from tabLead
|
||||
where ifnull(email_id, '') != '' %s""" % (conditions or ""))
|
||||
|
||||
elif self.doc.send_to_type=="Employee":
|
||||
self.send_to_doctype = "Employee"
|
||||
self.email_field = "company_email"
|
||||
|
||||
return frappe.conn.sql_list("""select
|
||||
return frappe.db.sql_list("""select
|
||||
if(ifnull(company_email, '')!='', company_email, personal_email) as email_id
|
||||
from `tabEmployee` where status='Active'""")
|
||||
|
||||
@@ -93,7 +93,7 @@ class DocType():
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
|
||||
if not frappe.flags.in_test:
|
||||
frappe.conn.auto_commit_on_many_writes = True
|
||||
frappe.db.auto_commit_on_many_writes = True
|
||||
|
||||
send(recipients = self.recipients, sender = sender,
|
||||
subject = self.doc.subject, message = self.doc.message,
|
||||
@@ -101,7 +101,7 @@ class DocType():
|
||||
ref_doctype = self.doc.doctype, ref_docname = self.doc.name)
|
||||
|
||||
if not frappe.flags.in_test:
|
||||
frappe.conn.auto_commit_on_many_writes = False
|
||||
frappe.db.auto_commit_on_many_writes = False
|
||||
|
||||
def validate_send(self):
|
||||
if self.doc.fields.get("__islocal"):
|
||||
@@ -116,9 +116,9 @@ class DocType():
|
||||
def get_lead_options():
|
||||
return {
|
||||
"sources": ["All"] + filter(None,
|
||||
frappe.conn.sql_list("""select distinct source from tabLead""")),
|
||||
frappe.db.sql_list("""select distinct source from tabLead""")),
|
||||
"statuses": ["All"] + filter(None,
|
||||
frappe.conn.sql_list("""select distinct status from tabLead"""))
|
||||
frappe.db.sql_list("""select distinct status from tabLead"""))
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ def create_lead(email_id):
|
||||
from frappe.model.doc import get_default_naming_series
|
||||
real_name, email_id = parseaddr(email_id)
|
||||
|
||||
if frappe.conn.get_value("Lead", {"email_id": email_id}):
|
||||
if frappe.db.get_value("Lead", {"email_id": email_id}):
|
||||
return
|
||||
|
||||
lead = frappe.bean({
|
||||
@@ -137,7 +137,7 @@ def create_lead(email_id):
|
||||
"lead_name": real_name or email_id,
|
||||
"status": "Contacted",
|
||||
"naming_series": get_default_naming_series("Lead"),
|
||||
"company": frappe.conn.get_default("company"),
|
||||
"company": frappe.db.get_default("company"),
|
||||
"source": "Email"
|
||||
})
|
||||
lead.insert()
|
||||
@@ -8,9 +8,9 @@ class TestNewsletter(unittest.TestCase):
|
||||
w = frappe.bean(test_records[0])
|
||||
w.insert()
|
||||
self.assertTrue("test_lead@example.com" in w.controller.get_recipients())
|
||||
frappe.conn.sql("""delete from `tabBulk Email`""")
|
||||
frappe.db.sql("""delete from `tabBulk Email`""")
|
||||
w.controller.send_emails()
|
||||
self.assertTrue(frappe.conn.get_value("Bulk Email", {"recipient": "test_lead@example.com"}))
|
||||
self.assertTrue(frappe.db.get_value("Bulk Email", {"recipient": "test_lead@example.com"}))
|
||||
|
||||
def test_get_recipients_lead_by_status(self):
|
||||
w = frappe.bean(test_records[0])
|
||||
@@ -33,7 +33,7 @@ class TestNewsletter(unittest.TestCase):
|
||||
w = frappe.bean(test_records[2])
|
||||
w.insert()
|
||||
self.assertTrue("test_custom2@example.com" in w.controller.get_recipients())
|
||||
self.assertTrue(frappe.conn.get("Lead",
|
||||
self.assertTrue(frappe.db.get("Lead",
|
||||
{"email_id": "test_custom2@example.com"}))
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class SupportMailbox(POP3Mailbox):
|
||||
thread_id = mail.get_thread_id()
|
||||
new_ticket = False
|
||||
|
||||
if not (thread_id and frappe.conn.exists("Support Ticket", thread_id)):
|
||||
if not (thread_id and frappe.db.exists("Support Ticket", thread_id)):
|
||||
new_ticket = True
|
||||
|
||||
ticket = add_support_communication(mail.subject, mail.content, mail.from_email,
|
||||
@@ -53,7 +53,7 @@ Original Query:
|
||||
msg = cstr(response))
|
||||
|
||||
def get_support_mails():
|
||||
if cint(frappe.conn.get_value('Email Settings', None, 'sync_support_mails')):
|
||||
if cint(frappe.db.get_value('Email Settings', None, 'sync_support_mails')):
|
||||
SupportMailbox()
|
||||
|
||||
def add_support_communication(subject, content, sender, docname=None, mail=None):
|
||||
|
||||
@@ -13,13 +13,13 @@ class DocType(TransactionBase):
|
||||
self.doclist = doclist
|
||||
|
||||
def get_sender(self, comm):
|
||||
return frappe.conn.get_value('Email Settings',None,'support_email')
|
||||
return frappe.db.get_value('Email Settings',None,'support_email')
|
||||
|
||||
def get_subject(self, comm):
|
||||
return '[' + self.doc.name + '] ' + (comm.subject or 'No Subject Specified')
|
||||
|
||||
def get_content(self, comm):
|
||||
signature = frappe.conn.get_value('Email Settings',None,'support_signature')
|
||||
signature = frappe.db.get_value('Email Settings',None,'support_signature')
|
||||
content = comm.content
|
||||
if signature:
|
||||
content += '<p>' + signature + '</p>'
|
||||
@@ -41,16 +41,16 @@ class DocType(TransactionBase):
|
||||
email_id = email.utils.parseaddr(email_id)
|
||||
if email_id:
|
||||
if not self.doc.lead:
|
||||
self.doc.lead = frappe.conn.get_value("Lead", {"email_id": email_id})
|
||||
self.doc.lead = frappe.db.get_value("Lead", {"email_id": email_id})
|
||||
if not self.doc.contact:
|
||||
self.doc.contact = frappe.conn.get_value("Contact", {"email_id": email_id})
|
||||
self.doc.contact = frappe.db.get_value("Contact", {"email_id": email_id})
|
||||
|
||||
if not self.doc.company:
|
||||
self.doc.company = frappe.conn.get_value("Lead", self.doc.lead, "company") or \
|
||||
frappe.conn.get_default("company")
|
||||
self.doc.company = frappe.db.get_value("Lead", self.doc.lead, "company") or \
|
||||
frappe.db.get_default("company")
|
||||
|
||||
def update_status(self):
|
||||
status = frappe.conn.get_value("Support Ticket", self.doc.name, "status")
|
||||
status = frappe.db.get_value("Support Ticket", self.doc.name, "status")
|
||||
if self.doc.status!="Open" and status =="Open" and not self.doc.first_responded_on:
|
||||
self.doc.first_responded_on = now()
|
||||
if self.doc.status=="Closed" and status !="Closed":
|
||||
@@ -65,6 +65,6 @@ def set_status(name, status):
|
||||
st.save()
|
||||
|
||||
def auto_close_tickets():
|
||||
frappe.conn.sql("""update `tabSupport Ticket` set status = 'Closed'
|
||||
frappe.db.sql("""update `tabSupport Ticket` set status = 'Closed'
|
||||
where status = 'Replied'
|
||||
and date_sub(curdate(),interval 15 Day) > modified""")
|
||||
|
||||
Reference in New Issue
Block a user