Merge pull request #188 from anandpdoshi/master

Allow attachments in support ticket
This commit is contained in:
Anand Doshi
2011-12-27 04:15:28 -08:00
3 changed files with 62 additions and 37 deletions

View File

@@ -0,0 +1,6 @@
def execute():
import webnotes
from webnotes.modules.module_manager import reload_doc
reload_doc('Support', 'DocType', 'Support Ticket')
from webnotes.model.code import get_obj
get_obj('DocType', 'Support Ticket').validate()

View File

@@ -33,6 +33,7 @@ class SupportMailbox(POP3Mailbox):
Updates message from support email as either new or reply Updates message from support email as either new or reply
""" """
from home import update_feed from home import update_feed
from webnotes.utils.file_manager import save_file, add_file_list
content, content_type = '[Blank Email]', 'text/plain' content, content_type = '[Blank Email]', 'text/plain'
if mail.text_content: if mail.text_content:
@@ -49,6 +50,8 @@ class SupportMailbox(POP3Mailbox):
st.make_response_record(content, mail.mail['From'], content_type) st.make_response_record(content, mail.mail['From'], content_type)
webnotes.conn.set(st.doc, 'status', 'Open') webnotes.conn.set(st.doc, 'status', 'Open')
update_feed(st.doc) update_feed(st.doc)
# extract attachments
self.save_attachments(doc=st.doc, attachment_list=mail.attachments)
return return
# new ticket # new ticket
@@ -61,6 +64,7 @@ class SupportMailbox(POP3Mailbox):
d.status = 'Open' d.status = 'Open'
try: try:
d.save(1) d.save(1)
# update feed # update feed
update_feed(d) update_feed(d)
@@ -71,6 +75,31 @@ class SupportMailbox(POP3Mailbox):
d.description = 'Unable to extract message' d.description = 'Unable to extract message'
d.save(1) d.save(1)
else:
# extract attachments
self.save_attachments(doc=d, attachment_list=mail.attachments)
def save_attachments(self, doc, attachment_list=[]):
"""
Saves attachments from email
attachment_list is a list of dict containing:
'filename', 'content', 'content-type'
"""
for attachment in attachment_list:
fid = save_file(
fname=attachment['filename'],
content=attachment['content'],
module='Support'
)
status = add_file_list('Support Ticket', doc.name, attachment['filename'], fid)
if not status:
doc.description = doc.description \
+ "\nCould not attach: " + str(attachment['filename'])
doc.save()
def send_auto_reply(self, d): def send_auto_reply(self, d):
""" """
Send auto reply to emails Send auto reply to emails

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-05-23 09:01:10', 'creation': '2011-05-23 10:00:38',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-25 14:45:28', 'modified': '2011-12-27 17:40:25',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
@@ -13,6 +13,7 @@
# These values are common for all DocType # These values are common for all DocType
{ {
'_last_update': '1311584009', '_last_update': '1311584009',
'allow_attach': 1,
'allow_trash': 1, 'allow_trash': 1,
'autoname': 'SUP.######', 'autoname': 'SUP.######',
'colour': 'White:FFF', 'colour': 'White:FFF',
@@ -25,7 +26,7 @@
'show_in_menu': 0, 'show_in_menu': 0,
'subject': '%(subject)s', 'subject': '%(subject)s',
'tag_fields': 'status,allocated_to', 'tag_fields': 'status,allocated_to',
'version': 144 'version': 149
}, },
# These values are common for all DocField # These values are common for all DocField
@@ -39,12 +40,14 @@
# These values are common for all DocPerm # These values are common for all DocPerm
{ {
'amend': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'name': '__common__', 'name': '__common__',
'parent': 'Support Ticket', 'parent': 'Support Ticket',
'parentfield': 'permissions', 'parentfield': 'permissions',
'parenttype': 'DocType', 'parenttype': 'DocType',
'read': 1 'read': 1,
'submit': 0
}, },
# DocType, Support Ticket # DocType, Support Ticket
@@ -55,23 +58,19 @@
# DocPerm # DocPerm
{ {
'amend': 0,
'cancel': 0, 'cancel': 0,
'create': 1, 'create': 1,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 1,
'permlevel': 0, 'permlevel': 0,
'role': 'Guest', 'role': 'Guest',
'submit': 0,
'write': 1 'write': 1
}, },
# DocPerm # DocPerm
{ {
'cancel': 0,
'create': 1, 'create': 1,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 2,
'match': 'customer',
'permlevel': 0, 'permlevel': 0,
'role': 'Customer', 'role': 'Customer',
'write': 1 'write': 1
@@ -82,7 +81,6 @@
'cancel': 1, 'cancel': 1,
'create': 1, 'create': 1,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 3,
'permlevel': 0, 'permlevel': 0,
'role': 'Support Team', 'role': 'Support Team',
'write': 1 'write': 1
@@ -93,8 +91,6 @@
'cancel': 0, 'cancel': 0,
'create': 0, 'create': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 4,
'match': 'allocated_to',
'permlevel': 1, 'permlevel': 1,
'role': 'Support Team', 'role': 'Support Team',
'write': 1 'write': 1
@@ -102,10 +98,12 @@
# DocPerm # DocPerm
{ {
'cancel': 0,
'create': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 5,
'permlevel': 2, 'permlevel': 2,
'role': 'Support Team' 'role': 'Support Team',
'write': 0
}, },
# DocField # DocField
@@ -115,7 +113,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'status', 'fieldname': 'status',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 1,
'in_filter': 0, 'in_filter': 0,
'label': 'Status', 'label': 'Status',
'no_copy': 1, 'no_copy': 1,
@@ -132,7 +129,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'subject', 'fieldname': 'subject',
'fieldtype': 'Text', 'fieldtype': 'Text',
'idx': 2,
'in_filter': 1, 'in_filter': 1,
'label': 'Subject', 'label': 'Subject',
'permlevel': 0, 'permlevel': 0,
@@ -145,7 +141,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'raised_by', 'fieldname': 'raised_by',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 3,
'in_filter': 1, 'in_filter': 1,
'label': 'Raised By (Email)', 'label': 'Raised By (Email)',
'oldfieldname': 'raised_by', 'oldfieldname': 'raised_by',
@@ -160,7 +155,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'description', 'fieldname': 'description',
'fieldtype': 'Text', 'fieldtype': 'Text',
'idx': 4,
'label': 'Description', 'label': 'Description',
'oldfieldname': 'problem_description', 'oldfieldname': 'problem_description',
'oldfieldtype': 'Text', 'oldfieldtype': 'Text',
@@ -173,7 +167,6 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 5,
'label': 'Thread HTML', 'label': 'Thread HTML',
'permlevel': 1 'permlevel': 1
}, },
@@ -184,7 +177,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'new_response', 'fieldname': 'new_response',
'fieldtype': 'Text', 'fieldtype': 'Text',
'idx': 6,
'label': 'New Response', 'label': 'New Response',
'permlevel': 0 'permlevel': 0
}, },
@@ -194,8 +186,8 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Button', 'fieldtype': 'Button',
'idx': 7,
'label': 'Send', 'label': 'Send',
'options': 'send_response',
'permlevel': 0 'permlevel': 0
}, },
@@ -204,7 +196,6 @@
'colour': 'White:FFF', 'colour': 'White:FFF',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'idx': 8,
'label': 'Additional Info', 'label': 'Additional Info',
'permlevel': 1 'permlevel': 1
}, },
@@ -214,7 +205,6 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 9,
'oldfieldtype': 'Column Break', 'oldfieldtype': 'Column Break',
'permlevel': 1, 'permlevel': 1,
'width': '50%' 'width': '50%'
@@ -226,7 +216,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'customer', 'fieldname': 'customer',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 10,
'in_filter': 1, 'in_filter': 1,
'label': 'Customer', 'label': 'Customer',
'oldfieldname': 'customer', 'oldfieldname': 'customer',
@@ -244,7 +233,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'customer_name', 'fieldname': 'customer_name',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 11,
'in_filter': 1, 'in_filter': 1,
'label': 'Customer Name', 'label': 'Customer Name',
'oldfieldname': 'customer_name', 'oldfieldname': 'customer_name',
@@ -259,7 +247,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'address_display', 'fieldname': 'address_display',
'fieldtype': 'Small Text', 'fieldtype': 'Small Text',
'idx': 12,
'label': 'Address', 'label': 'Address',
'permlevel': 2 'permlevel': 2
}, },
@@ -269,7 +256,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'contact_display', 'fieldname': 'contact_display',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 13,
'label': 'Contact Name', 'label': 'Contact Name',
'permlevel': 2 'permlevel': 2
}, },
@@ -279,7 +265,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'contact_mobile', 'fieldname': 'contact_mobile',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 14,
'label': 'Mobile No', 'label': 'Mobile No',
'permlevel': 2 'permlevel': 2
}, },
@@ -289,7 +274,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'contact_email', 'fieldname': 'contact_email',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 15,
'label': 'Contact Email', 'label': 'Contact Email',
'oldfieldname': 'contact_no', 'oldfieldname': 'contact_no',
'oldfieldtype': 'Data', 'oldfieldtype': 'Data',
@@ -302,7 +286,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'opening_date', 'fieldname': 'opening_date',
'fieldtype': 'Date', 'fieldtype': 'Date',
'idx': 16,
'label': 'Opening Date', 'label': 'Opening Date',
'no_copy': 1, 'no_copy': 1,
'oldfieldname': 'opening_date', 'oldfieldname': 'opening_date',
@@ -315,7 +298,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'opening_time', 'fieldname': 'opening_time',
'fieldtype': 'Time', 'fieldtype': 'Time',
'idx': 17,
'label': 'Opening Time', 'label': 'Opening Time',
'no_copy': 1, 'no_copy': 1,
'oldfieldname': 'opening_time', 'oldfieldname': 'opening_time',
@@ -328,18 +310,17 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 18,
'oldfieldtype': 'Column Break', 'oldfieldtype': 'Column Break',
'permlevel': 1 'permlevel': 1
}, },
# DocField # DocField
{ {
'colour': 'White:FFF',
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'allocated_to', 'fieldname': 'allocated_to',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 19,
'in_filter': 1, 'in_filter': 1,
'label': 'Allocated To', 'label': 'Allocated To',
'oldfieldname': 'allocated_to', 'oldfieldname': 'allocated_to',
@@ -355,7 +336,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'resolution_details', 'fieldname': 'resolution_details',
'fieldtype': 'Text', 'fieldtype': 'Text',
'idx': 20,
'label': 'Resolution Details', 'label': 'Resolution Details',
'no_copy': 1, 'no_copy': 1,
'oldfieldname': 'resolution_details', 'oldfieldname': 'resolution_details',
@@ -365,11 +345,11 @@
# DocField # DocField
{ {
'colour': 'White:FFF',
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'resolution_date', 'fieldname': 'resolution_date',
'fieldtype': 'Date', 'fieldtype': 'Date',
'idx': 21,
'in_filter': 0, 'in_filter': 0,
'label': 'Resolution Date', 'label': 'Resolution Date',
'no_copy': 1, 'no_copy': 1,
@@ -385,7 +365,6 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'resolution_time', 'fieldname': 'resolution_time',
'fieldtype': 'Time', 'fieldtype': 'Time',
'idx': 22,
'label': 'Resolution Time', 'label': 'Resolution Time',
'oldfieldname': 'resolution_time', 'oldfieldname': 'resolution_time',
'oldfieldtype': 'Time', 'oldfieldtype': 'Time',
@@ -399,8 +378,19 @@
'fieldname': 'content_type', 'fieldname': 'content_type',
'fieldtype': 'Data', 'fieldtype': 'Data',
'hidden': 1, 'hidden': 1,
'idx': 23,
'label': 'Content Type', 'label': 'Content Type',
'permlevel': 0 'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'file_list',
'fieldtype': 'Text',
'hidden': 1,
'label': 'File List',
'no_copy': 1,
'permlevel': 0,
'print_hide': 1
} }
] ]