Merge pull request #1942 from anandpdoshi/anand-july-16

Fixes in Setup Wizard and Support Ticket
This commit is contained in:
Anand Doshi
2014-07-16 13:17:50 +05:30
2 changed files with 35 additions and 26 deletions

View File

@@ -113,9 +113,11 @@ def update_user_name(args):
last_name=%(last_name)s WHERE name=%(name)s""", args) last_name=%(last_name)s WHERE name=%(name)s""", args)
if args.get("attach_user"): if args.get("attach_user"):
filename, filetype, content = args.get("attach_user").split(",") attach_user = args.get("attach_user").split(",")
fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url if len(attach_user)==3:
frappe.db.set_value("User", args.get("name"), "user_image", fileurl) filename, filetype, content = attach_user
fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
frappe.db.set_value("User", args.get("name"), "user_image", fileurl)
add_all_roles_to(args.get("name")) add_all_roles_to(args.get("name"))
@@ -319,9 +321,11 @@ def create_items(args):
}).insert() }).insert()
if args.get("item_img_" + str(i)): if args.get("item_img_" + str(i)):
filename, filetype, content = args.get("item_img_" + str(i)).split(",") item_image = args.get("item_img_" + str(i)).split(",")
fileurl = save_file(filename, content, "Item", item, decode=True).file_url if len(item_image)==3:
frappe.db.set_value("Item", item, "image", fileurl) filename, filetype, content = item_image
fileurl = save_file(filename, content, "Item", item, decode=True).file_url
frappe.db.set_value("Item", item, "image", fileurl)
def create_customers(args): def create_customers(args):
for i in xrange(1,6): for i in xrange(1,6):
@@ -374,17 +378,21 @@ def create_letter_head(args):
"is_default": 1 "is_default": 1
}).insert() }).insert()
filename, filetype, content = args.get("attach_letterhead").split(",") attach_letterhead = args.get("attach_letterhead").split(",")
fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url if len(attach_letterhead)==3:
frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl) filename, filetype, content = attach_letterhead
fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url
frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl)
def create_logo(args): def create_logo(args):
if args.get("attach_logo"): if args.get("attach_logo"):
filename, filetype, content = args.get("attach_logo").split(",") attach_logo = args.get("attach_logo").split(",")
fileurl = save_file(filename, content, "Website Settings", "Website Settings", if len(attach_logo)==3:
decode=True).file_url filename, filetype, content = attach_logo
frappe.db.set_value("Website Settings", "Website Settings", "banner_html", fileurl = save_file(filename, content, "Website Settings", "Website Settings",
"<img src='%s' style='max-width: 100%%;'>" % fileurl) decode=True).file_url
frappe.db.set_value("Website Settings", "Website Settings", "banner_html",
"<img src='%s' style='max-width: 100%%;'>" % fileurl)
def add_all_roles_to(name): def add_all_roles_to(name):
user = frappe.get_doc("User", name) user = frappe.get_doc("User", name)

View File

@@ -8,31 +8,31 @@ from erpnext.utilities.transaction_base import TransactionBase
from frappe.utils import now, extract_email_id from frappe.utils import now, extract_email_id
class SupportTicket(TransactionBase): class SupportTicket(TransactionBase):
def get_sender(self, comm): def get_sender(self, comm):
return frappe.db.get_value('Support Email Settings',None,'support_email') return frappe.db.get_value('Support Email Settings',None,'support_email')
def get_subject(self, comm): def get_subject(self, comm):
return '[' + self.name + '] ' + (comm.subject or 'No Subject Specified') return '[' + self.name + '] ' + (comm.subject or 'No Subject Specified')
def get_content(self, comm): def get_content(self, comm):
signature = frappe.db.get_value('Support Email Settings',None,'support_signature') signature = frappe.db.get_value('Support Email Settings',None,'support_signature')
content = comm.content content = comm.content
if signature: if signature:
content += '<p>' + signature + '</p>' content += '<p>' + signature + '</p>'
return content return content
def get_portal_page(self): def get_portal_page(self):
return "ticket" return "ticket"
def validate(self): def validate(self):
self.update_status() self.update_status()
self.set_lead_contact(self.raised_by) self.set_lead_contact(self.raised_by)
if self.status == "Closed": if self.status == "Closed":
from frappe.widgets.form.assign_to import clear from frappe.widgets.form.assign_to import clear
clear(self.doctype, self.name) clear(self.doctype, self.name)
def set_lead_contact(self, email_id): def set_lead_contact(self, email_id):
import email.utils import email.utils
email_id = email.utils.parseaddr(email_id) email_id = email.utils.parseaddr(email_id)
@@ -41,8 +41,8 @@ class SupportTicket(TransactionBase):
self.lead = frappe.db.get_value("Lead", {"email_id": email_id}) self.lead = frappe.db.get_value("Lead", {"email_id": email_id})
if not self.contact: if not self.contact:
self.contact = frappe.db.get_value("Contact", {"email_id": email_id}) self.contact = frappe.db.get_value("Contact", {"email_id": email_id})
if not self.company: if not self.company:
self.company = frappe.db.get_value("Lead", self.lead, "company") or \ self.company = frappe.db.get_value("Lead", self.lead, "company") or \
frappe.db.get_default("company") frappe.db.get_default("company")
@@ -53,15 +53,16 @@ class SupportTicket(TransactionBase):
if self.status=="Closed" and status !="Closed": if self.status=="Closed" and status !="Closed":
self.resolution_date = now() self.resolution_date = now()
if self.status=="Open" and status !="Open": if self.status=="Open" and status !="Open":
self.resolution_date = "" # if no date, it should be set as None and not a blank string "", as per mysql strict config
self.resolution_date = None
@frappe.whitelist() @frappe.whitelist()
def set_status(name, status): def set_status(name, status):
st = frappe.get_doc("Support Ticket", name) st = frappe.get_doc("Support Ticket", name)
st.status = status st.status = status
st.save() st.save()
def auto_close_tickets(): def auto_close_tickets():
frappe.db.sql("""update `tabSupport Ticket` set status = 'Closed' frappe.db.sql("""update `tabSupport Ticket` set status = 'Closed'
where status = 'Replied' where status = 'Replied'
and date_sub(curdate(),interval 15 Day) > modified""") and date_sub(curdate(),interval 15 Day) > modified""")